Here is my java solution


  • 0
    C
    public class Solution {
        public int titleToNumber(String s) {
            int colnum= 0;
            for (int i = 0; i < s.length(); i++){
                char c = s.charAt(i);
                int pos = c - 'A' + 1;
                colnum=(int)(colnum+Math.pow(26,(s.length()-i-1))*pos);
            }
            return colnum;
        }
    }

  • 0
    D

    will this work for case sensitive inputs like 'aa' as well?


Log in to reply
 

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