#171. Excel表列序号
思路:简单的进制转换,注意A是1,不是0,要加1即可
/**
* 171. Excel表列序号
*
*/
public class Solution171 {
public int titleToNumber(String s) {
int res = 0;
char[] chars = s.toCharArray();
for (char ch : chars) {
int temp = (ch- 'A') + 1;
res = res * 26 + temp;
}
return res;
}
public static void main(String[] args) {
Solution171 solution171 = new Solution171();
System.out.println(solution171.titleToNumber("A"));
}
}