Skip to content

Commit a5b068f

Browse files
committed
create 0168-excel-sheet-column-title.cs
1 parent e984baa commit a5b068f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class Solution {
2+
3+
private const int _ASCII_BASE = 64;
4+
5+
public string ConvertToTitle(int columnNumber)
6+
{
7+
StringBuilder sb = new StringBuilder();
8+
9+
while (columnNumber > 0)
10+
{
11+
int rest = columnNumber % 26;
12+
rest = rest == 0 ? 26 : rest;
13+
14+
sb.Insert(0, (char)(rest + _ASCII_BASE));
15+
16+
columnNumber -= rest;
17+
columnNumber /= 26;
18+
}
19+
20+
return sb.ToString();
21+
}
22+
}

0 commit comments

Comments
 (0)