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
shifting-letters.cpp 423 Bytes
Copy Edit Raw Blame History
kamyu authored 2018-06-10 16:16 +08:00 . Update shifting-letters.cpp
// Time: O(n)
// Space: O(1)
class Solution {
public:
string shiftingLetters(string S, vector<int>& shifts) {
string result;
auto times = accumulate(shifts.cbegin(), shifts.cend(), 0L) % 26;
for (int i = 0; i < S.length(); ++i) {
result.push_back('a' + (S[i] - 'a' + times) % 26);
times = ((times - shifts[i]) % 26 + 26) % 26;
}
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