|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- Given a column title as appear in an Excel sheet, return its corresponding column number.
- For example:
- A -> 1
- B -> 2
- C -> 3
- ...
- Z -> 26
- AA -> 27
- AB -> 28
- ...
- Example 1:
- Input: "A"
- Output: 1
- Example 2:
- Input: "AB"
- Output: 28
- Example 3:
- Input: "ZY"
- Output: 701
复制代码
- class Solution {
- public int titleToNumber(String s) {
- if(s.length() == 0) return 0;
-
- if(s.length()>1)
- return (s.charAt(0) - 'A'+1)*((int)Math.pow(26,s.length() - 1)) + titleToNumber(s.substring(1));
- else return (s.charAt(0) - 'A'+1)*((int)Math.pow(26,s.length() - 1));
- }
- }
复制代码 |
|