Skip to content

Commit 5ed7e66

Browse files
Create 0171-excel-sheet-column-number.cs
1 parent 3128895 commit 5ed7e66

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Solution {
2+
public int TitleToNumber(string columnTitle) {
3+
int result = 0;
4+
char[] chars = columnTitle.ToCharArray().Reverse().ToArray();
5+
6+
for (int index = 0; index < chars.Length; index++) {
7+
char currentChar = chars[index];
8+
int delta = currentChar - 'A' + 1;
9+
int sum = delta * (int)Math.Pow(26, index);
10+
11+
result += sum;
12+
}
13+
14+
return result;
15+
}
16+
}

0 commit comments

Comments
 (0)