和另一道题相反,把英文字母的26进制转换成10进制。思路非常清晰。

 

public class Solution {
    public int titleToNumber(String s) {
        int ans = 0;
        for(int i=s.length()-1; i>=0; i--) {
            char ch = s.charAt(i);
            if(i == s.length()-1)
                ans += (int)(ch  -'A' + 1);
            else
                ans += (int)(ch  -'A' + 1) * Math.pow(26, (s.length()-1-i));
                
        }
        
        return ans;
    }
}               

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-20
  • 2021-11-07
  • 2022-12-23
猜你喜欢
  • 2021-07-05
  • 2021-05-27
  • 2021-08-07
  • 2022-01-18
  • 2022-02-24
  • 2021-09-09
相关资源
相似解决方案