File tree Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * @lc app=leetcode id=168 lang=java
3
+ *
4
+ * [168] Excel Sheet Column Title
5
+ *
6
+ * https://leetcode.com/problems/excel-sheet-column-title/description/
7
+ *
8
+ * algorithms
9
+ * Easy (29.44%)
10
+ * Likes: 810
11
+ * Dislikes: 164
12
+ * Total Accepted: 182.7K
13
+ * Total Submissions: 620K
14
+ * Testcase Example: '1'
15
+ *
16
+ * Given a positive integer, return its corresponding column title as appear in
17
+ * an Excel sheet.
18
+ *
19
+ * For example:
20
+ *
21
+ *
22
+ * 1 -> A
23
+ * 2 -> B
24
+ * 3 -> C
25
+ * ...
26
+ * 26 -> Z
27
+ * 27 -> AA
28
+ * 28 -> AB
29
+ * ...
30
+ *
31
+ *
32
+ * Example 1:
33
+ *
34
+ *
35
+ * Input: 1
36
+ * Output: "A"
37
+ *
38
+ *
39
+ * Example 2:
40
+ *
41
+ *
42
+ * Input: 28
43
+ * Output: "AB"
44
+ *
45
+ *
46
+ * Example 3:
47
+ *
48
+ *
49
+ * Input: 701
50
+ * Output: "ZY"
51
+ *
52
+ */
53
+ class Solution {
54
+ public String convertToTitle (int n ) {
55
+ StringBuilder sb = new StringBuilder ();
56
+ while (n != 0 ) {
57
+ sb .insert (0 , (char )((n -1 )%26 + 'A' ));
58
+ n = (n -1 ) / 26 ;
59
+ }
60
+ return sb .toString ();
61
+ }
62
+ }
63
+
You can’t perform that action at this time.
0 commit comments