s4553711
5/8/2017 - 2:29 PM

441.cpp

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