Skip to content

Commit 7a6bb4b

Browse files
authored
Update arranging-coins.cpp
1 parent 4e023e4 commit 7a6bb4b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

C++/arranging-coins.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@ class Solution {
1313
class Solution2 {
1414
public:
1515
int arrangeCoins(int n) {
16-
long long left = 1, right = n;
16+
uint64_t left = 1, right = n;
1717
while (left <= right) {
1818
const auto mid = left + (right - left) / 2;
19-
if (2L * n < mid * (mid + 1)) {
19+
if (!check(mid, n)) {
2020
right = mid - 1;
2121
} else {
2222
left = mid + 1;
2323
}
2424
}
25-
return left - 1;
25+
return right;
26+
}
27+
28+
private:
29+
bool check(uint64_t mid, uint64_t n) {
30+
return mid <= 2L * n / (mid + 1);
2631
}
2732
};

0 commit comments

Comments
 (0)