首页 > 其他 > 详细

Excel Sheet Column Title

时间:2014-12-21 00:41:09      阅读:308      评论:0      收藏:0      [点我收藏+]

Excel Sheet Column Title

 

Given a non-zero 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 

参考:http://www.cnblogs.com/ganganloveu/p/4175848.html
这道题以为很easy,但还是参考了别人的才A出来了
java中能用StringBuffer还是用StringBuffer,感觉StringBuffer要比String要好用一点
 1 public class Solution {
 2    public String convertToTitle(int n) {
 3         StringBuffer result = new StringBuffer();
 4         while(n > 0){
 5             n--;
 6             int temp = n % 26 + 65;
 7             result.append((char)temp);
 8             n = n / 26;
 9             
10         }
11         for(int i = 0, j = result.length() - 1; i < j;i++, j--){
12             char temp = result.charAt(i);
13             result.setCharAt(i, result.charAt(j));
14             result.setCharAt(j, temp);
15             
16         }
17         return result.toString();
18     }
19 }

 

Excel Sheet Column Title

原文:http://www.cnblogs.com/luckygxf/p/4176067.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!