Clean, Efficient and Self-Explanatory Java Code


  • 0
    C
      public int titleToNumber(String s) {
            if(null==s)
                return -1;
            double result = 0;
            char[] arr = s.toCharArray();
            for(int i=0; i<arr.length; i++){
                result = result + Math.pow(26,arr.length-1-i)*(arr[i]+1-'A');
            }
            return (int) result;
        }

Log in to reply
 

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