-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Certseeds/dev
feature: update version 0.8.2
- Loading branch information
Showing
64 changed files
with
2,243 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
// SPDX-License-Identifier: MIT | ||
/* | ||
CS203_DSAA_template | ||
Copyright (C) 2022 nanoseeds | ||
*/ | ||
#include "leetcode_830_test.hpp" | ||
|
||
namespace leetcode_830 { | ||
|
||
vector<vector<int32_t>> leetcode_830::largeGroupPositions(const string &S) { | ||
int end{1}, length{1}; | ||
vector<vector<int32_t>> willreturn{}; | ||
const auto s_size{static_cast<int32_t>(S.size())}; | ||
for (int32_t i{1}; i < s_size; ++i) { | ||
end = i; | ||
if (S[i] == S[i - 1]) { | ||
length++; | ||
} else { | ||
if (length >= 3) { | ||
willreturn.push_back({end - length, end - 1}); | ||
} | ||
length = 1; | ||
} | ||
} | ||
if (length >= 3) { | ||
willreturn.push_back({end - length + 1, end}); | ||
} | ||
return willreturn; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: MIT | ||
/* | ||
CS203_DSAA_template | ||
Copyright (C) 2022 nanoseeds | ||
*/ | ||
//@Tag array | ||
//@Tag 数组 | ||
#ifndef CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_830_TEST_HPP | ||
#define CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_830_TEST_HPP | ||
|
||
#include <catch_main.hpp> | ||
#include <cstdint> | ||
#include <cstddef> | ||
#include <vector> | ||
#include <string> | ||
|
||
namespace leetcode_830 { | ||
using std::vector; | ||
using std::string; | ||
|
||
struct leetcode_830 { | ||
static vector<vector<int32_t>> largeGroupPositions(const string &s); | ||
}; | ||
|
||
using Catch::Matchers::Equals; | ||
|
||
TEST_CASE("test case 1 [test_830]", "[test_830]") { | ||
static constexpr const char *const input{"abbxxxxzzy"}; | ||
const vector<vector<int32_t>> output{{3, 6}}; | ||
CHECK_THAT(output, Equals(leetcode_830::largeGroupPositions(input))); | ||
} | ||
|
||
TEST_CASE("test case 2 [test_830]", "[test_830]") { | ||
static constexpr const char *const input{"abc"}; | ||
const vector<vector<int32_t>> output{}; | ||
CHECK_THAT(output, Equals(leetcode_830::largeGroupPositions(input))); | ||
} | ||
|
||
TEST_CASE("test case 3 [test_830]", "[test_830]") { | ||
static constexpr const char *const input{"abcdddeeeeaabbbcd"}; | ||
const vector<vector<int32_t>> output{{3, 5}, {6, 9}, {12, 14}}; | ||
CHECK_THAT(output, Equals(leetcode_830::largeGroupPositions(input))); | ||
} | ||
TEST_CASE("test case 4 [test_830]", "[test_830]") { | ||
static constexpr const char *const input{"abz"}; | ||
const vector<vector<int32_t>> output{}; | ||
CHECK_THAT(output, Equals(leetcode_830::largeGroupPositions(input))); | ||
} | ||
} | ||
#endif //CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_830_TEST_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-License-Identifier: MIT | ||
/* | ||
CS203_DSAA_template | ||
Copyright (C) 2022 nanoseeds | ||
*/ | ||
#include "leetcode_832_test.hpp" | ||
|
||
namespace leetcode_832 { | ||
|
||
vector<vector<int>> leetcode_832::flipAndInvertImageConst(const vector<vector<int>> &image) { | ||
const auto m{image.size()}; | ||
if (m == 0) { | ||
return image; | ||
} | ||
const auto n{image.front().size()}; | ||
if (n == 0) { | ||
return image; | ||
} | ||
vector<vector<int32_t>> result(image); | ||
vector<uint8_t> traverse(n); | ||
for (size_t i{0}; i < m; ++i) { | ||
for (size_t left{0}, right{n - 1}; left < right && right < n; ++left, --right) { | ||
if (image[i][left] == image[i][right]) { | ||
result[i][left] = !image[i][left]; | ||
result[i][right] = !image[i][right]; | ||
} | ||
} | ||
if (n % 2 == 1) { | ||
result[i][n / 2] = !image[i][n / 2]; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: MIT | ||
/* | ||
CS203_DSAA_template | ||
Copyright (C) 2022 nanoseeds | ||
*/ | ||
//@Tag array | ||
//@Tag 数组 | ||
#ifndef CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_832_TEST_HPP | ||
#define CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_832_TEST_HPP | ||
|
||
#include <catch_main.hpp> | ||
#include <cstdint> | ||
#include <cstddef> | ||
#include <vector> | ||
|
||
namespace leetcode_832 { | ||
using std::vector; | ||
|
||
struct leetcode_832 { | ||
static vector<vector<int32_t>> flipAndInvertImageConst(const vector<vector<int32_t>> &image); | ||
|
||
}; | ||
|
||
using Catch::Matchers::Equals; | ||
|
||
TEST_CASE("test case 1 [test_832]", "[test_832]") { | ||
const vector<vector<int32_t>> inputs{{1, 1, 0}, | ||
{1, 0, 1}, | ||
{0, 0, 0}}; | ||
const vector<vector<int32_t>> result{ | ||
{1, 0, 0}, | ||
{0, 1, 0}, | ||
{1, 1, 1}, | ||
}; | ||
CHECK_THAT(result, Equals(leetcode_832::flipAndInvertImageConst(inputs))); | ||
} | ||
|
||
TEST_CASE("test case 2 [test_832]", "[test_832]") { | ||
const vector<vector<int32_t>> inputs{{1, 1, 0, 0}, | ||
{1, 0, 0, 1}, | ||
{0, 1, 1, 1}, | ||
{1, 0, 1, 0} | ||
}; | ||
const vector<vector<int32_t>> result{ | ||
{1, 1, 0, 0}, | ||
{0, 1, 1, 0}, | ||
{0, 0, 0, 1}, | ||
{1, 0, 1, 0} | ||
}; | ||
CHECK_THAT(result, Equals(leetcode_832::flipAndInvertImageConst(inputs))); | ||
} | ||
|
||
} | ||
#endif //CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_832_TEST_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: MIT | ||
/* | ||
CS203_DSAA_template | ||
Copyright (C) 2022 nanoseeds | ||
*/ | ||
#include "leetcode_840_test.hpp" | ||
|
||
namespace leetcode_840 { | ||
|
||
bool numMagicSquaresInside_help(const vector<vector<int>> &grid, size_t x, size_t y) { | ||
for (size_t i{0}; i < 3; ++i) { | ||
for (size_t j{0}; j < 3; ++j) { | ||
if (grid[x + i][y + j] > 9 || grid[x + i][y + j] < 1) { | ||
return false; | ||
} | ||
} | ||
} | ||
return ( | ||
// 中间需要是五 | ||
grid[x + 1][y + 1] == 5 && | ||
grid[x][y] + grid[x + 2][y + 2] == 10 && | ||
grid[x + 1][y] + grid[x + 1][y + 2] == 10 && | ||
grid[x + 2][y] + grid[x][y + 2] == 10 && | ||
grid[x][y] != grid[x + 2][y + 2] && | ||
grid[x + 1][y] != grid[x + 1][y + 2] && | ||
grid[x + 2][y] != grid[x][y + 2] && | ||
grid[x][y] + grid[x][y + 1] + grid[x][y + 2] == 15 && | ||
grid[x][y] + grid[x + 1][y] + grid[x + 2][y] == 15 && | ||
grid[x + 2][y] + grid[x + 2][y + 1] + grid[x + 2][y + 2] == 15 | ||
); | ||
} | ||
|
||
int leetcode_840::numMagicSquaresInside(const vector<vector<int>> &grid) { | ||
const auto m{grid.size()}; | ||
if (m < 3) { | ||
return 0; | ||
} | ||
const auto n{grid.size()}; | ||
if (n < 3) { | ||
return 0; | ||
} | ||
int count = 0; | ||
for (size_t i{0}; i + 3 <= m; ++i) { | ||
for (size_t j{0}; j + 3 <= n; ++j) { | ||
count += numMagicSquaresInside_help(grid, i, j); | ||
} | ||
} | ||
return count; | ||
} | ||
} |
Oops, something went wrong.