Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit33bbbdf

Browse files
author
applewjg
committed
Excel Sheet Column Title
Change-Id: Ic0bc978a6ca4a3bd065d8d60f58a089630e100bd
1 parent9643a3b commit33bbbdf

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎ExcelSheetColumnTitle.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Author: King, wangjingui@outlook.com
3+
Date: Dec 19, 2014
4+
Problem: Excel Sheet Column Title
5+
Difficulty: Easy
6+
Source: https://oj.leetcode.com/problems/excel-sheet-column-title/
7+
Notes:
8+
Given a non-zero positive integer, return its corresponding column title as appear in an Excel sheet.
9+
10+
For example:
11+
12+
1 -> A
13+
2 -> B
14+
3 -> C
15+
...
16+
26 -> Z
17+
27 -> AA
18+
28 -> AB
19+
20+
Solution: 1. Iteration.
21+
2&3. recursion.
22+
*/
23+
publicclassSolution {
24+
publicStringconvertToTitle(intn) {
25+
StringBuffersb =newStringBuffer();
26+
while (n >0) {
27+
sb.insert(0,(char)((n -1)%26 +'A'));
28+
n = (n -1) /26;
29+
}
30+
returnsb.toString();
31+
}
32+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp