Skip to content

Commit cc03aee

Browse files
Add files via upload
1 parent e3a70e0 commit cc03aee

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// 注意如何更加高效的,不使用pow函数来完成
2+
// Runtime: 8 ms, faster than 99.60% of C++ online submissions for Excel Sheet Column Number.
3+
// Memory Usage: 7.9 MB, less than 99.32% of C++ online submissions for Excel Sheet Column Number.
4+
5+
class Solution
6+
{
7+
public:
8+
int titleToNumber(string s)
9+
{
10+
// 讲道理如果这里不使用long而使用int回导致溢出
11+
long sum = 0;
12+
for (int i = 0; i < s.length(); i++)
13+
sum = sum * 26 + s[i] - 'A' + 1;
14+
return sum;
15+
}
16+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Runtime: 52 ms, faster than 99.35% of Python3 online submissions for Excel Sheet Column Number.
2+
# Memory Usage: 12.5 MB, less than 85.71% of Python3 online submissions for Excel Sheet Column Number.
3+
4+
class Solution:
5+
def titleToNumber(self, s: 'str') -> 'int':
6+
sum = 0
7+
for i in range(len(s)):
8+
sum = sum * 26 + ord(s[i]) - 64
9+
return sum

0 commit comments

Comments
 (0)