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
excel-sheet-column-number.cpp 544 Bytes
Copy Edit Raw Blame History
kamyu authored 2019-01-04 14:09 +08:00 . Update excel-sheet-column-number.cpp
// Time: O(n)
// Space: O(1)
class Solution {
public:
int titleToNumber(string s) {
int number = 0;
for (const auto& c : s) {
number *= 26;
number += c - 'A' + 1;
}
return number;
}
};
// Time: O(n)
// Space: O(1)
class Solution2 {
public:
int titleToNumber(string s) {
return accumulate(s.cbegin(), s.cend(), 0,
[](int sum, char c) {
return sum * 26 + c - 'A' + 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