码迷,mamicode.com
首页 > 其他好文 > 详细

excel sheet column number

时间:2015-09-11 06:44:00      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

 

 

 

 

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

[分析]
26进制转10进制

[注意事项]
1)s == null的处理

[Code]

 

 1 public class Solution {
 2     public int titleToNumber(String s) 
 3     {
 4         int num =0;
 5         if (s==null) return num;
 6         for (int i =0;i<s.length();i++)
 7         {
 8             num=num*26+(s.charAt(i)-‘A‘+1);
 9         }
10         
11         return num;
12         
13     }
14 }

 

reference: http://www.danielbit.com/blog/puzzle/leetcode/leetcode-excel-sheet-column-number

excel sheet column number

标签:

原文地址:http://www.cnblogs.com/hygeia/p/4799839.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!