Simple Solution for Java


  • 4
    Z
    public class Solution {
        public String convertToTitle(int n) {
            char[] alpha = "ZABCDEFGHIJKLMNOPQRSTUVWXY".toCharArray();
            String s = "";
            while(n != 0){
                s = alpha[n % 26] + s;
                if(n % 26 == 0)
                    n -= 26;
                n /= 26;
            }
            return s;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.