Skip to content

Commit 141f891

Browse files
committed
Update index.hpp
1 parent 0a28775 commit 141f891

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

check-if-it-is-a-good-array/index.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <vector>
55

66
using namespace std;
7+
#include<numeric>
8+
#include <algorithm>
79
//template <class InputIt, class T, class BinaryOperation>
810
//constexpr // since C++20
911
// T
@@ -14,21 +16,21 @@ using namespace std;
1416

1517
// return init;
1618
//};
17-
int gcd2(int num1, int num2)
19+
int gcd(int num1, int num2)
1820
{
19-
while (num2 != 0) {
20-
int temp = num1;
21-
num1 = num2;
21+
while (num2 != 0) {
22+
int temp = num1;
23+
num1 = num2;
2224
num2 = temp % num2;
23-
}
25+
}
2426
return num1;
2527
};
2628

2729
class Solution {
2830
public:
2931
bool isGoodArray(vector<int>& nums)
3032
{
31-
int divisor = accumulate(nums.begin(), nums.end(), nums[0], gcd2);
33+
int divisor = accumulate<std::vector<int>::iterator, int, int(int, int)>(nums.begin(), nums.end(), nums[0], gcd);
3234
return divisor == 1;
3335
}
3436
};

0 commit comments

Comments
 (0)