LeetCode之171. Excel Sheet Column Number

LeetCode之171. Excel Sheet Column Number

----------------------------------

乘权相加即可。

AC代码:(从右往左)

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

精简版AC代码:(从左往右)

public class Solution {
public int titleToNumber(String s) {
int res=0;
for(int i=0;i<s.length();i++) res=res*26+s.charAt(i)-'A'+1;
return res;
}
}

题目来源: https://leetcode.com/problems/excel-sheet-column-number/

上一篇:ORA-29275: partial multibyte character


下一篇:VC中遍历目标进程中的模块