Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB
class Solution { public String convertToTitle(int n) { String str = new String("ZABCDEFGHIJKLMNOPQRSTUVWXY"); StringBuilder res = new StringBuilder(); while(n>0){ res.insert(0,String.valueOf(str.charAt(n%26))); if(n %26 == 0) n--; n /= 26; } return res.toString(); } }
[参与人数: 0 平均分: 0/5]
版权申明:本站原创文章皆遵循“署名-非商业性使用-相同方式共享 3.0 (CC BY-NC-SA 3.0)”。转载请保留以下标注:原文来源:《168. Excel Sheet Column Title》
发表评论