首页 > 代码库 > LeetCode 168. Excel Sheet Column Title

LeetCode 168. Excel Sheet Column Title

进制转换

 

public class Solution {        char[] letter;        public String convertToTitle(int n) {        init();        StringBuilder sb = new StringBuilder();                n--;        if( n == 0) return "A";                while(n >= 0) {            sb.insert(0, letter[n%26]);                        if(n == 0) break;            n /= 26;            n--;        }        return sb.toString();    }        public void init() {        letter = new char[26];        for(int i = 0; i < 26; i++)            letter[i] = (char)(‘A‘+i);    }    }

  

LeetCode 168. Excel Sheet Column Title