Leetcode 441 Solution
This article provides solution to leetcode question 441 (arranging-coins)
Access this page by simply typing in "lcs 441" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/arranging-coins
Solution
class Solution {
public:
int arrangeCoins(int n) {
int64_t l = 0;
int64_t r = 1000000;
while (l <= r)
{
int64_t m = (l + r) / 2;
int64_t v = m * (m + 1) / 2;
if (n < v)
r = m - 1;
else
l = m + 1;
}
return r;
}
};