Java: ten - line solution


  • 0
    public class Solution {
        public int titleToNumber(String s) {
            int cur = 1, res = 0;
            for(int i = s.length() - 1; i >= 0; i--){
                res += (s.charAt(i) - 'A' + 1) * cur;
                cur *= 26;
            }
            return res;
        }
    }
    

Log in to reply
 

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