Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
arranging-coins.cpp 565 Bytes
Copy Edit Raw Blame History
kamyu authored 2016-10-31 23:26 +08:00 . Update arranging-coins.cpp
// Time: O(logn)
// Space: O(1)
class Solution {
public:
int arrangeCoins(int n) {
return static_cast<int>((sqrt(8.0 * n + 1) - 1) / 2);
}
};
// Time: O(logn)
// Space: O(1)
class Solution2 {
public:
int arrangeCoins(int n) {
long long left = 1, right = n;
while (left <= right) {
const auto mid = left + (right - left) / 2;
if (2L * n < mid * (mid + 1)) {
right = mid - 1;
} else {
left = mid + 1;
}
}
return left - 1;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search