class Solution {
public:
int arrangeCoins(int n) {
if(n <= 1) return n;
long left = 0, right = n;
while(left <= right){
long mid = left + (right  left)/2;
long sum = ((1 + mid) * mid)/2;
if(sum <= n){left = mid + 1;}
else {right = mid  1;}
}
return left  1;
}
};
C++_9ms_Accepted

@jasonshieh said in C++_9ms_Accepted:
class Solution {
public:
int arrangeCoins(int n) {
if(n <= 1) return n;
long left = 0, right = n;
while(left <= right){
long mid = left + (right  left)/2;
long sum = ((1 + mid) * mid)/2;
if(sum <= n){left = mid + 1;}
else {right = mid  1;}
}
return left  1;
}
};