Skip to content

Commit

Permalink
pre-for-release v0.8.3
Browse files Browse the repository at this point in the history
</subject>

Branch: master

<type>:
- [ ] Bug fix
- [ ] Bug fix (Test)
- [x] New feature
- [ ] Breaking change
- [ ] Documentation update
- [ ] This change requires a documentation update

<body>

<footer>

Signed-off-by: Certseeds <[email protected]>
  • Loading branch information
Certseeds committed Jun 19, 2022
2 parents 7994547 + 1a2d42d commit 7553c71
Show file tree
Hide file tree
Showing 17 changed files with 501 additions and 241 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,12 @@ jobs:
tree
- name: release
uses: "marvinpinto/action-automatic-releases@latest"
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "${{steps.branch_name.outputs.SOURCE_TAG}}"
prerelease: false
title: "${{steps.branch_name.outputs.SOURCE_TAG}}"
files: ./../script_no_need.zip
prerelease: false
generate_release_notes: true

- name: tree
run: tree
Expand Down
3 changes: 2 additions & 1 deletion algorithm/array/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ list(APPEND leetcode_order 747 766 1606 48 59)
list(APPEND leetcode_order 334 238 560 804 806)
list(APPEND leetcode_order 807 811 830 832 840)
list(APPEND leetcode_order 849 852 867 868 896)
list(APPEND leetcode_order 905 908 922)
list(APPEND leetcode_order 905 908 922 941 942)
list(APPEND leetcode_order 944 977)
LIST(TRANSFORM leetcode_order PREPEND leetcode_)

set(dependencies ${dependencies} ${leetcode_order})
Expand Down
31 changes: 31 additions & 0 deletions algorithm/array/leetcode_941.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
#include "leetcode_941_test.hpp"

namespace leetcode_941 {

bool leetcode_941::validMountainArray(const vector<int32_t> &arr) {
const auto arr_size{arr.size()};
if (arr_size < 3) {
return false;
} else if (arr_size == 3) {
return arr[0] < arr[1] && arr[1] > arr[2];
}
size_t count{0};
for (size_t i{1}; i + 1 < arr_size; ++i) {
if (arr[i - 1] == arr[i] || arr[i] == arr[i + 1]) {
return false;
}
count += (arr[i - 1] < arr[i]) == (arr[i] < arr[i + 1]);
}
if (count + 3 == arr_size) {
return true;
}
return false;
}
}
51 changes: 51 additions & 0 deletions algorithm/array/leetcode_941_test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
//@Tag array
//@Tag
#ifndef CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_941_TEST_HPP
#define CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_941_TEST_HPP

#include <catch_main.hpp>
#include <cstdint>
#include <cstddef>
#include <vector>

namespace leetcode_941 {
using std::vector;

struct leetcode_941 {
static bool validMountainArray(const vector<int32_t> &arr);
};


TEST_CASE("test case 1 {test_941}", "{test_941}") {
const vector<int32_t> input{4, 5, 10, 7};
CHECK(leetcode_941::validMountainArray(input));
}

TEST_CASE("test case 2 {test_941}", "{test_941}") {
const vector<int32_t> input{0, 3, 2, 1};
CHECK(leetcode_941::validMountainArray(input));
}

TEST_CASE("test case 3 {test_941}", "{test_941}") {
const vector<int32_t> input{114, 514, 191};
CHECK(leetcode_941::validMountainArray(input));
}

TEST_CASE("test case 4 {test_941}", "{test_941}") {
const vector<int32_t> input{1, 8, 0};
CHECK(leetcode_941::validMountainArray(input));
}

TEST_CASE("test case 5 {test_941}", "{test_941}") {
const vector<int32_t> input{9, 1, 9};
CHECK_FALSE(leetcode_941::validMountainArray(input));
}
}
#endif //CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_941_TEST_HPP
29 changes: 29 additions & 0 deletions algorithm/array/leetcode_942.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
#include "leetcode_942_test.hpp"

namespace leetcode_942 {

vector<int32_t> leetcode_942::diStringMatch(const string &str) {
const auto str_size{str.size()};
int32_t min{0}, max{static_cast<int32_t>(str_size)};
vector<int32_t> willreturn(max + 1);
for (size_t i{0}; i < str_size; i++) {
if (str[i] == 'I') {
willreturn[i] = min;
min++;
} else {
willreturn[i] = max;
max--;
}
}
willreturn.back() = min;
return willreturn;
}

}
55 changes: 55 additions & 0 deletions algorithm/array/leetcode_942_test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
//@Tag array
//@Tag
#ifndef CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_942_TEST_HPP
#define CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_942_TEST_HPP

#include <catch_main.hpp>
#include <cstdint>
#include <cstddef>
#include <vector>
#include <string>

namespace leetcode_942 {
using std::vector;
using std::string;

struct leetcode_942 {
static vector<int> diStringMatch(const string &str);
};

static void check(const string &str, const vector<int32_t> &vec) {
const auto str_size{str.size()}, vec_size{vec.size()};
CHECK(str_size + 1 == vec_size);
for (size_t i{0}; i < str_size; ++i) {
CHECK((str[i] == 'I' || str[i] == 'D'));
if (str[i] == 'I') {
CHECK(vec[i] < vec[i + 1]);
} else {
CHECK(vec[i] > vec[i + 1]);
}
}
}

TEST_CASE("test case 1 {test_942}", "{test_942}") {
static constexpr const char *const str{"IDID"};
check(str, leetcode_942::diStringMatch(str));
}

TEST_CASE("test case 2 {test_942}", "{test_942}") {
static constexpr const char *const str{"III"};
check(str, leetcode_942::diStringMatch(str));
}

TEST_CASE("test case 3 {test_942}", "{test_942}") {
static constexpr const char *const str{"DDI"};
check(str, leetcode_942::diStringMatch(str));
}
}
#endif //CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_942_TEST_HPP
25 changes: 25 additions & 0 deletions algorithm/array/leetcode_944.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
#include "leetcode_944_test.hpp"

namespace leetcode_944 {

int leetcode_944::minDeletionSize(const vector<string> &strs) {
int count{0};
const auto lines{strs.size()};
const auto str_size{strs[0].size()};
for (size_t i{0},notdeletex{true}; i < str_size; ++i,notdeletex = true) {
for (size_t j{1}; j < lines; ++j) {
notdeletex = notdeletex & (strs[j][i] >= strs[j - 1][i]);
}
count += !notdeletex;
}
return count;
}

}
50 changes: 50 additions & 0 deletions algorithm/array/leetcode_944_test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
//@Tag array
//@Tag
#ifndef CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_944_TEST_HPP
#define CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_944_TEST_HPP

#include <catch_main.hpp>
#include <cstdint>
#include <cstddef>
#include <vector>
#include <string>

namespace leetcode_944 {
using std::vector;
using std::string;

struct leetcode_944 {
static int minDeletionSize(const vector<string> &A);
};

TEST_CASE("test case 1 {test_944}", "{test_944}") {
static constexpr const std::array<const char *const, 3> input{
"abc", "bce", "cae"
};
static constexpr const auto result{1};
CHECK(result == leetcode_944::minDeletionSize({input.begin(), input.end()}));
}

TEST_CASE("test case 2 {test_944}", "{test_944}") {
static constexpr const std::array<const char *const, 2> input{
"a", "b"
};
static constexpr const auto result{0};
CHECK(result == leetcode_944::minDeletionSize({input.begin(), input.end()}));
}
TEST_CASE("test case 3 {test_944}", "{test_944}") {
static constexpr const std::array<const char *const, 3> input{
"zyx", "wvu", "tsr"
};
static constexpr const auto result{3};
CHECK(result == leetcode_944::minDeletionSize({input.begin(), input.end()}));
}
}
#endif //CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_944_TEST_HPP
36 changes: 36 additions & 0 deletions algorithm/array/leetcode_977.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
#include "leetcode_977_test.hpp"

namespace leetcode_977 {

// best O(n)
vector<int32_t> leetcode_977::sortedSquares(const vector<int32_t> &nums) {
const auto nums_size{nums.size()};
static constexpr const auto cmp = [](int32_t x, int32_t y) {
return x * x <= y * y;
};
vector<int32_t> will_return{};
const size_t posi = std::min_element(nums.cbegin(), nums.cend(), cmp) - nums.cbegin();
size_t left{posi + 1}, right{posi + 1};
while (0 < left && right < nums_size) {
const auto cmpValue = cmp(nums[left - 1], nums[right]);
if (cmpValue) {
will_return.push_back(nums[left - 1] * nums[left - 1]);
--left;
} else {
will_return.push_back(nums[right] * nums[right]);
++right;
}
}
for (; 0 < left; --left) { will_return.push_back(nums[left - 1] * nums[left - 1]); }
for (; right < nums_size; ++right) { will_return.push_back(nums[right] * nums[right]); }
return will_return;
}

}
41 changes: 41 additions & 0 deletions algorithm/array/leetcode_977_test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
//@Tag array
//@Tag
#ifndef CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_977_TEST_HPP
#define CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_977_TEST_HPP

#include <catch_main.hpp>
#include <cstdint>
#include <cstddef>
#include <vector>
#include <string>

namespace leetcode_977 {
using std::vector;
using std::string;

struct leetcode_977 {
static vector<int32_t> sortedSquares(const vector<int32_t> &nums);
};

using Catch::Matchers::Equals;

TEST_CASE("test case 1 {test_977}", "{test_977}") {
const vector<int32_t> input{-4, -1, 0, 3, 10};
const vector<int32_t> result{0, 1, 9, 16, 100};
CHECK_THAT(result, Equals(leetcode_977::sortedSquares(input)));
}

TEST_CASE("test case 2 {test_977}", "{test_977}") {
const vector<int32_t> input{-7, -3, 2, 3, 11};
const vector<int32_t> result{4, 9,9, 49, 121};
CHECK_THAT(result, Equals(leetcode_977::sortedSquares(input)));
}
}
#endif //CS203_DSAA_TEMPLATE_ALGORITHM_ARRAY_LEETCODE_977_TEST_HPP
2 changes: 1 addition & 1 deletion algorithm/associative_container/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ enable_testing()
set(dependencies)

set(leetcode_order 888 890 893 1409 914)
list(APPEND leetcode_order 929)
list(APPEND leetcode_order 929 961)
LIST(TRANSFORM leetcode_order PREPEND leetcode_)

set(dependencies ${dependencies} ${leetcode_order})
Expand Down
26 changes: 26 additions & 0 deletions algorithm/associative_container/leetcode_961.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
#include "leetcode_961_test.hpp"
#include <unordered_set>

namespace leetcode_961 {
using std::unordered_set;

int32_t leetcode_961::repeatedNTimes(const vector<int32_t> &nums) {
unordered_set<int32_t> uset{};
for (const auto num: nums) {
if (uset.count(num) != 0) {
return num;
} else {
uset.insert(num);
}
}
return -1;
}

}
Loading

0 comments on commit 7553c71

Please sign in to comment.