Skip to content

Commit

Permalink
feat: update lc-1390
Browse files Browse the repository at this point in the history
Signed-off-by: Certseeds <[email protected]>
  • Loading branch information
Certseeds committed Sep 4, 2023
1 parent 7d74146 commit 3daede5
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
2 changes: 1 addition & 1 deletion algorithm/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LIST(APPEND leetcode_order 118_119 169 217 263)
LIST(APPEND leetcode_order 268 283 338 343 372)
LIST(APPEND leetcode_order 401 414 461 728 781)
LIST(APPEND leetcode_order 136 75 883 1018 1185)
LIST(APPEND leetcode_order 670 1252 1362 1363)
LIST(APPEND leetcode_order 670 1252 1362 1363 1390)
LIST(TRANSFORM leetcode_order PREPEND leetcode_)

set(dependencies ${dependencies} ${leetcode_order})
Expand Down
36 changes: 36 additions & 0 deletions algorithm/math/leetcode_1390.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@


// SPDX-License-Identifier: AGPL-3.0-or-later
/*
CS203_DSAA_template
Copyright (C) 2020-2023 nanoseeds
*/
#include "leetcode_1390_test.hpp"
#include <cmath>

namespace leetcode_1390 {

int32_t leetcode_1390::sumFourDivisors(const vector<int32_t> &nums) {
int32_t will_return{0};
for (const auto &num: nums) {
int32_t count{0}, sum{0};
for (int32_t i{1}; i <= std::sqrt(num) && count <= 4; ++i) {
if (num % i == 0) {
count += 1;
sum += i;
if (i * i != num) {
count += 1;
sum += num / i;
}
}
}
if (count == 4) {
will_return += sum;
}
}
return will_return;
}

}
40 changes: 40 additions & 0 deletions algorithm/math/leetcode_1390_test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@


// SPDX-License-Identifier: AGPL-3.0-or-later
/*
CS203_DSAA_template
Copyright (C) 2022 nanoseeds
*/
//@Tag 数学
#ifndef CS203_DSAA_TEMPLATE_ALGORITHM_LIST_LEETCODE_1390_TEST_HPP
#define CS203_DSAA_TEMPLATE_ALGORITHM_LIST_LEETCODE_1390_TEST_HPP

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

namespace leetcode_1390 {

namespace leetcode_1390 {
int32_t sumFourDivisors(const vector<int32_t> &nums);
}

using Catch::Matchers::Equals;

TEST_CASE("1-1 [test_1390]", "[test_1390]") {
const vector<int32_t> input{1, 1, 4, 5, 1, 4};
constexpr const auto result{0};
CHECK(result == leetcode_1390::sumFourDivisors(input));
}

TEST_CASE("1-2 [test_1390]", "[test_1390]") {
const vector<int32_t> input{21, 4, 7};
constexpr const auto result{32};
CHECK(result == leetcode_1390::sumFourDivisors(input));
}
}
#endif //CS203_DSAA_TEMPLATE_ALGORITHM_LIST_LEETCODE_1390_TEST_HPP

4 changes: 2 additions & 2 deletions algorithm/tree/leetcode_1372.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ int32_t leetcode_1372::longestZigZag(TreeNode *root) {
maximum = std::max(maximum, v);
}
if (head->left != nullptr) {
que.push({head->left, true});
que.emplace(head->left, true);
}
if (head->right != nullptr) {
que.push({head->right, false});
que.emplace(head->right, false);
}
}
return maximum;
Expand Down

0 comments on commit 3daede5

Please sign in to comment.