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
2-keys-keyboard.cpp 385 Bytes
Copy Edit Raw Blame History
kamyu authored 2017-08-06 19:53 +08:00 . Create 2-keys-keyboard.cpp
// Time: O(sqrt(n))
// Space: O(1)
class Solution {
public:
int minSteps(int n) {
auto result = 0;
// the answer is the sum of prime factors
for (auto p = 2 ; p * p <= n; ++p) {
while (n % p == 0) {
result += p;
n /= p;
}
}
result += (n > 1) ? n : 0;
return result;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search