Skip to content

Commit 21b1764

Browse files
committed
update
1 parent 1a5a8ed commit 21b1764

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Python/excel-sheet-column-number.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
#
4+
# Related to question Excel Sheet Column Title
5+
#
6+
# Given a column title as appear in an Excel sheet, return its corresponding column number.
7+
#
8+
# For example:
9+
#
10+
# A -> 1
11+
# B -> 2
12+
# C -> 3
13+
# ...
14+
# Z -> 26
15+
# AA -> 27
16+
# AB -> 28
17+
#
18+
19+
class Solution:
20+
# @param s, a string
21+
# @return an integer
22+
def titleToNumber(self, s):
23+
result = 0
24+
for i in xrange(len(s)):
25+
result *= 26
26+
result += ord(s[i]) - ord('A') + 1
27+
return result
28+
29+
if __name__ == "__main__":
30+
print Solution().titleToNumber("AAAB")

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
LeetCode
22
========
33

4-
Up to date (2014-12-26), there are total `170` problems on [LeetCode Online Judge](https://oj.leetcode.com/).
4+
Up to date (2014-12-27), there are total `171` problems on [LeetCode Online Judge](https://oj.leetcode.com/).
55
The number of problems is increasing recently.
6-
Here is the classification of all `170` problems.
6+
Here is the classification of all `171` problems.
77
I'll keep updating for full summary and better solutions. Stay tuned for updates.
88

99
---
@@ -305,6 +305,7 @@ Problem | Solution | Time | Space | Difficul
305305
--------------- | --------------- | --------------- | --------------- | -------------- | -----
306306
[Divide Two Integers] | [divide-two-integers.py] | _O(logn)_ | _O(1)_ | Medium |
307307
[Excel Sheet Column Title] | [excel-sheet-column-title.py] | _O(logn)_ | _O(1)_ | Easy |
308+
[Excel Sheet Column Number] | [excel-sheet-column-number.py] | _O(n)_ | _O(1)_ | Easy |
308309
[Fraction to Recurring Decimal] | [fraction-to-recurring-decimal.py] | _O(logn)_ | _O(1)_ | Medium |
309310
[Gray Code] | [gray-code.py] | _O(2^n)_ | _O(1)_ | Medium |
310311
[Integer to Roman] | [integer-to-roman.py] | _O(n)_ | _O(1)_ | Medium |
@@ -318,6 +319,8 @@ Problem | Solution | Time | Space | Difficul
318319
[divide-two-integers.py]:https://github.com/kamyu104/LeetCode/blob/master/Python/divide-two-integers.py
319320
[Excel Sheet Column Title]:https://oj.leetcode.com/problems/excel-sheet-column-title/
320321
[excel-sheet-column-title.py]:https://github.com/kamyu104/LeetCode/blob/master/Python/excel-sheet-column-title.py
322+
[Excel Sheet Column Number]:https://oj.leetcode.com/problems/excel-sheet-column-number/
323+
[excel-sheet-column-number.py]:https://github.com/kamyu104/LeetCode/blob/master/Python/excel-sheet-column-number.py
321324
[Fraction to Recurring Decimal]:https://oj.leetcode.com/problems/fraction-to-recurring-decimal/
322325
[fraction-to-recurring-decimal.py]:https://github.com/kamyu104/LeetCode/blob/master/Python/fraction-to-recurring-decimal.py
323326
[Gray Code]:https://oj.leetcode.com/problems/gray-code/

0 commit comments

Comments
 (0)