LeetCode 168. Excel Sheet Column Title

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 168: Excel Sheet Column Title

LeetCode 168. Excel Sheet Column Title

LeetCode 168. Excel Sheet Column Title

[leetcode-168-Excel Sheet Column Title]

LeetCode168. Excel Sheet Column Title

Leetcode 168. Excel Sheet Column Title