Skip to content

Commit ef0bcf7

Browse files
committed
refactor code
1 parent 64e0982 commit ef0bcf7

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

cpp-algorithm/src/dynamic_programming/fibonacci_number.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22

33
auto Fibonacci::FibonacciDynamicTopDown(const int number, std::vector<int>& memo) -> int
44
{
5-
if (number == 0) { return 0; }
6-
if (number == 1) { return 1; }
7-
if (memo[number] > 0) { return memo[number]; }
5+
if (number == 0)
6+
{
7+
return 0;
8+
}
9+
if (number == 1)
10+
{
11+
return 1;
12+
}
13+
if (memo[number] > 0)
14+
{
15+
return memo[number];
16+
}
817

918
memo[number] = FibonacciDynamicTopDown(number - 1, memo) + FibonacciDynamicTopDown(number - 2, memo);
1019

@@ -13,8 +22,14 @@ auto Fibonacci::FibonacciDynamicTopDown(const int number, std::vector<int>& memo
1322

1423
auto Fibonacci::FibonacciDynamicBottomUp(const int number) -> int
1524
{
16-
if (number == 0) { return 0; }
17-
if (number == 1) { return 1; }
25+
if (number == 0)
26+
{
27+
return 0;
28+
}
29+
if (number == 1)
30+
{
31+
return 1;
32+
}
1833

1934
std::vector<int> memo(number + 1, -1);
2035
memo[0] = 0;

cpp-algorithm/src/primitive_type/compute_parity.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22

33
#include <array>
44

5-
auto BuildTable() -> std::array<short, 1 << 16>
6-
{
7-
std::array<short, 1 << 16> result{};
8-
for (auto i = 0; i < (1 << 16); ++i)
9-
{
10-
result[i] = ComputingParity::Parity(i);
11-
}
12-
return result;
13-
}
14-
155
auto ComputingParity::CountBits(unsigned int x) -> short
166
{
177
short num_bits = 0;
@@ -45,6 +35,16 @@ auto ComputingParity::ParityDropLowestBits(unsigned long long x) -> short
4535
return result;
4636
}
4737

38+
auto BuildTable() -> std::array<short, 1 << 16>
39+
{
40+
std::array<short, 1 << 16> result{};
41+
for (auto i = 0; i < (1 << 16); ++i)
42+
{
43+
result[i] = ComputingParity::Parity(i);
44+
}
45+
return result;
46+
}
47+
4848
auto ComputingParity::ParityLookupTable(const unsigned long long x) -> short
4949
{
5050
constexpr auto mask_size = 16;

cpp-algorithm/src/search/search_sorted_matrix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ bool SearchSortedMatrix::SearchSortedMatrix(const std::vector<std::vector<int>>&
1010
// matrix is empty, return false
1111
if (matrix.empty() || matrix[0].empty())
1212
{
13-
return false;
13+
return false;
1414
}
1515

1616
const auto row_size = static_cast<int>(matrix.size());

0 commit comments

Comments
 (0)