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
decoded-string-at-index.cpp 618 Bytes
Copy Edit Raw Blame History
kamyu authored 2018-08-07 10:21 +08:00 . Create decoded-string-at-index.cpp
// Time: O(n)
// Space: O(1)
class Solution {
public:
string decodeAtIndex(string S, int K) {
uint64_t n = 0;
for (int i = 0; i < S.length(); ++i) {
if (isdigit(S[i])) {
n *= S[i] - '0';
} else {
++n;
}
}
for (int i = S.length() - 1; i >= 0; --i) {
K %= n;
if (K == 0 && isalpha(S[i])) {
return (string) "" + S[i];
}
if (isdigit(S[i])) {
n /= S[i] - '0';
} else {
--n;
}
}
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search