IrisJavaDiary
Friday, October 6, 2017
168. Excel Sheet Column Title
5.18 %
class Solution {
public String convertToTitle(int n) {
if (n <= 0) return null;
StringBuilder sb = new StringBuilder();
while (n > 0) {
n--;
sb.insert(0, (char)('A' + n % 26));
n /= 26;
}
return sb.toString();
}
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment