-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path168.java
More file actions
36 lines (32 loc) · 1.17 KB
/
168.java
File metadata and controls
36 lines (32 loc) · 1.17 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
__________________________________________________________________________________________________
sample 35040 kb submission
public class Solution {
public String convertToTitle(int columnNumber) {
StringBuilder columnName = new StringBuilder();
while (columnNumber > 0){
int rem = columnNumber % 26;
if (rem == 0){
columnName.append("Z");
columnNumber = (columnNumber / 26) - 1;
}else{
columnName.append((char)((rem - 1) + 'A'));
columnNumber = columnNumber / 26;
}
}
return columnName.reverse().toString();
}
}
__________________________________________________________________________________________________
sample 35044 kb submission
class Solution {
public String convertToTitle(int n) {
StringBuilder builder = new StringBuilder();
while (n > 0) {
n--;
builder.insert(0, (char) (n % 26 + 'A'));
n /= 26;
}
return builder.toString();
}
}
__________________________________________________________________________________________________