Java - Simple solution


  • 0
    T
    public class Solution {
        public int titleToNumber(String s) {
            if(s.isEmpty())return 0;
            int result = 1+(s.charAt(0)-'A')%26;
            int i = 1;
            while(i<s.length()){
                result = (result*26)+(1+ (s.charAt(i)-'A')%26 );
                i++;
            }
            return result;
        }
    }
    

Log in to reply
 

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