Simple 0ms java solution


  • 1
    J
    public class Solution {
        public String convertToTitle(int n) {
            String title = "";
            while(n > 0){
                int remainder = (n-1) % 26;
                title = (char)('A' + remainder) + title;
                n = (n - 1) / 26;
            }
            return title;
        }
    }

  • 0
    S

    Great! But the last line in the while loop should be n = (n - reminder - 1) / 26;


Log in to reply
 

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