题目:https://leetcode-cn.com/problems/excel-sheet-column-number/
代码:
class Solution { public int titleToNumber(String s) { int ans = 0; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); ans = ans * 26 + (c - 'A' + 1); } return ans; } }
思路:
根据题目意思,其实就是一个进制转换问题,即26进制转10进制。