My solution in java


  • 0
    M
     public static int titleToNumber(String s) {
        if(s.length()==0||s==null)
           return 0;
        int len=s.length();
        int temp=len;
        double res=0;
        while(len>0){
            res=res+Math.pow(26,temp-len)*(s.charAt(len-1)-'A'+1);
            len--;
        }
        return (int)res;
    }

Log in to reply
 

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