Skip to content

Commit 8a573b4

Browse files
committed
excel_sheet_column_title
1 parent c816394 commit 8a573b4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Golang solution for leetcode. For each problem, there is a simple *_test.go to t
145145
#### [165. compare version numbers](https://github.com/hitzzc/go-leetcode/tree/master/compare_version_numbers)
146146
#### [166. Fraction to Recurring Decimal](https://github.com/hitzzc/go-leetcode/tree/master/fraction_to_recurring_decimal)
147147
#### [167. Two Sum II](https://github.com/hitzzc/go-leetcode/tree/master/two_sum_II)
148-
148+
#### [168. Excel Sheet Column Title](https://github.com/hitzzc/go-leetcode/tree/master/excel_sheet_column_title)
149149

150150

151151

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package excel_sheet_column_title
2+
3+
func convertToTitle(n int) string {
4+
if n == 0 {
5+
return ""
6+
}
7+
bytes := []byte{}
8+
var remainder int
9+
for n > 0 {
10+
remainder = (n - 1) % 26
11+
bytes = append(bytes, 'A'+byte(remainder))
12+
n = (n - 1) / 26
13+
}
14+
for i, j := 0, len(bytes)-1; i < j; i, j = i+1, j-1 {
15+
bytes[i], bytes[j] = bytes[j], bytes[i]
16+
}
17+
return string(bytes)
18+
}

0 commit comments

Comments
 (0)