- Notifications
You must be signed in to change notification settings - Fork 366
/
Copy pathLeetcode168.java
39 lines (33 loc) · 934 Bytes
/
Leetcode168.java
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
packagecom.company;
publicclassLeetcode168 {
publicstaticvoidmain(String[] args) {
intcolumnNumber=701;
Stringanswer=convertToTitle(columnNumber);
System.out.println(answer);
}
publicstaticStringconvertToTitle(intcolumnNumber) {
intn=columnNumber,x=0,y=0;
StringcolumnTitle="";
while (n>=1){
x=n/26;
if (x==0){
y=n+64;
columnTitle=columnTitle+(char)y;
n=n/26;
}
if (x>=1 && x<=26){
y=x+64;
columnTitle=columnTitle+(char)y;
break;
}
if (x>26){
y=x%26;
y=y+64;
columnTitle=columnTitle+(char)y;
n=n/26;
}
}
columnTitle=columnTitle+(char)((columnNumber%26)+64);
returncolumnTitle;
}
}