Question: 441. Arranging Coins
Intution:
Time Complexity:
Space Complexity:
Solution:
class Solution {
public int arrangeCoins(int n) {
long low = 1;
long high = n;
while (low <= high) {
long mid = low + (high - low) / 2;
if (2l * n == mid * (mid + 1)) return (int) mid;
else if (2l * n < mid * (mid + 1)) high = mid - 1;
else low = mid + 1;
}
return (int) high;
}
}