Easy rescursive java 3ms solution.


  • 0
    O
    public class Solution {
        public int titleToNumber(String s) {
            if(s.length() == 1) return s.charAt(0)-'A'+1;
            return s.charAt(s.length()-1)-'A'+1
                +26*titleToNumber(s.substring(0,s.length()>1?s.length()-1:0));
        }
    }
    

Log in to reply
 

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