Java 2MS solution


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

  • 0
    B

    why? can you explain it?


  • 0
    T

    consider it as an array, each array consists of another 26 arrays! or u can think every 26 characters construct a line, multify means find the right line, plus means find the right column!


Log in to reply
 

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