Java O(n) sharing


  • 1
    Z
    public class Solution {
        public int titleToNumber(String s) 
        {
            int sum = 0;
            s = s.toUpperCase();
            for (int i = 0; i < s.length(); i++)
            {
                sum = 26 * sum + (s.charAt(i) - ZERO);
            }
            return sum;
        }
        
        private static final int ZERO = 'A' - 1;
    }

Log in to reply
 

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