-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString168.java
More file actions
50 lines (49 loc) · 1.02 KB
/
String168.java
File metadata and controls
50 lines (49 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package string;
/**
* @ProjectName: leetcode
* @Package: string
* @ClassName: String168
* @Author: markey
* @Description:168. Excel表列名称
* 给定一个正整数,返回它在 Excel 表中相对应的列名称。
*
* 例如,
*
* 1 -> A
* 2 -> B
* 3 -> C
* ...
* 26 -> Z
* 27 -> AA
* 28 -> AB
* ...
* 示例 1:
*
* 输入: 1
* 输出: "A"
* 示例 2:
*
* 输入: 28
* 输出: "AB"
* 示例 3:
*
* 输入: 701
* 输出: "ZY"
*
* 来源:力扣(LeetCode)
* 链接:https://leetcode-cn.com/problems/excel-sheet-column-title
* 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
* @Date: 2020/3/14 17:02
* @Version: 1.0
*/
public class String168 {
public String convertToTitle(int n) {
if (n == 0) {
return "";
}
StringBuilder sb = new StringBuilder();
sb.append(convertToTitle(n/26));
sb.append((char)('A' + n%26));
return sb.toString();
}
}