Skip to content

Commit 1c7f9e1

Browse files
committed
"Excel Sheet Column Number"
1 parent cde439a commit 1c7f9e1

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ them with C++ Language.
2323
| 174 | [Dungeon Game] | |
2424
| 173 | [Binary Search Tree Iterator] | |
2525
| 172 | [Factorial Trailing Zeroes] | [C](src/172.c) |
26-
| 171 | [Excel Sheet Column Number] | |
26+
| 171 | [Excel Sheet Column Number] | [C](src/171.c) |
2727
| 170 | [Two Sum III - Data structure design] | |
2828
| 169 | [Majority Element] | [C](src/169.c) |
2929
| 168 | [Excel Sheet Column Title] | [C](src/168.c) |

src/171.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
4+
int titleToNumber(char *s) {
5+
int len = strlen(s);
6+
int i = 0;
7+
int ans = 0;
8+
while (i < len) {
9+
ans = ans * 26 + s[i] - 'A' + 1;
10+
i++;
11+
}
12+
13+
return ans;
14+
}
15+
16+
int main() {
17+
char s1[] = "Z";
18+
char s2[] = "AB";
19+
20+
printf("%d\n", titleToNumber(s1));
21+
printf("%d\n", titleToNumber(s2));
22+
return 0;
23+
}

0 commit comments

Comments
 (0)