public class Solution {
public int arrangeCoins(int n) {
int lo = 0, hi = n;
while(lo<=hi){
long mid = lo + (hilo)/2, a = (1+mid), b = (2+mid);
if(a*mid/2<=(long)n && a*b/2>(long)n) return (int)mid;
else if(a*mid/2>(long)n) hi = (int)mid1;
else lo = (int)mid + 1;
}
return lo;
}
}
``
Share my easy & simple Java Binary Search Solution


@zebra1831 to prevent integer overflow. left + right could overflow, whereas right  left couldn't.