JAVA - 2ms - looking for better


  • 0
    N

    here is my code.

    public class Solution {
        public int titleToNumber(String s) {
            int result = 0;
            
            if (s == null || s.isEmpty()) return result;
    
            char offset = 'A' - 1;
            
            for (int i = 0; i < s.length(); i++) {
                result = result * 26 + (s.charAt(i) - offset);
            }   
            return result;
        }
    }
    

Log in to reply
 

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