class Solution {
public:
int arrangeCoins(int n) {
int left = 1, right = n;
while (left < right) {
int mid = (right - left + 1) / 2 + left;
if ((long long) mid * (mid + 1) <= (long long) 2 * n) {
left = mid;
} else {
right = mid - 1;
}
}
return left;
}
};
leetcode每日一题第139天
最新推荐文章于 2024-11-04 12:20:00 发布