leetcode 171、Excel表列序號

題目大意:

給定一個Excel表格中的列名稱,返回其相應的列序號。

代碼:

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章