File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ package _168 ;
2
+
3
+ class Solution {
4
+ public String convertToTitle (int n ) {
5
+ StringBuilder s = new StringBuilder ();
6
+
7
+ while (n > 0 ) {
8
+ int r = n % 26 ;
9
+ r = (r == 0 ) ? 26 : r ;
10
+ String tmp = Character .toString ((char ) (r + 64 ));
11
+ s .insert (0 , tmp );
12
+ n = (n - r ) / 26 ;
13
+ }
14
+
15
+ return s .toString ();
16
+ }
17
+
18
+ public static void main (String [] args ) {
19
+ System .out .println (new Solution ().convertToTitle (703 ));
20
+ System .out .println (new Solution ().convertToTitle (52 ));
21
+ System .out .println (new Solution ().convertToTitle (1 ));
22
+ System .out .println (new Solution ().convertToTitle (26 ));
23
+ System .out .println (new Solution ().convertToTitle (28 ));
24
+ System .out .println (new Solution ().convertToTitle (701 ));
25
+ System .out .println (new Solution ().convertToTitle (800 ));
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments