We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7cdf772 commit 8100cafCopy full SHA for 8100caf
30 Days August Challange/Week 2/4. Excel Sheet Column Number/solution.py
@@ -0,0 +1,39 @@
1
+"""
2
+Given a column title as appear in an Excel sheet, return its corresponding column number.
3
+
4
+For example:
5
6
+ A -> 1
7
+ B -> 2
8
+ C -> 3
9
+ ...
10
+ Z -> 26
11
+ AA -> 27
12
+ AB -> 28
13
14
+Example 1:
15
16
+Input: "A"
17
+Output: 1
18
+Example 2:
19
20
+Input: "AB"
21
+Output: 28
22
+Example 3:
23
24
+Input: "ZY"
25
+Output: 701
26
27
28
+Constraints:
29
30
+1 <= s.length <= 7
31
+s consists only of uppercase English letters.
32
+s is between "A" and "FXSHRXW".
33
34
+class Solution:
35
+ def titleToNumber(self, s: str) -> int:
36
+ result = 0
37
+ for i,char in enumerate(s[::-1]):
38
+ result += (ord(char) - ord('A') + 1 ) * (26**i)
39
+ return result
0 commit comments