LeetCode Excel Sheet Column Number

来源:互联网 发布:找鼠标软件 编辑:程序博客网 时间:2024/06/03 19:24

原题链接在这里:https://leetcode.com/problems/excel-sheet-column-number/

这道题与Excel Sheet Column Title相呼应。Time O(n), Space O(1).

注意cast时后面的数要加个整体的括号。

AC Java:

public class Solution {    public int titleToNumber(String s) {        if(s == null || s.length() == 0)            return 0;                int res = 0;            for(int i = 0; i < s.length(); i++){            res= res + (int)((s.charAt(i)-64)*Math.pow(26,s.length()-i-1));        }                return res;            }}


0 0