Love丶FFC's Blog
给定Excel工作表中显示的列名称,返回其对应的列号。
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
样例1
输入: "AB"
输出: 28
样例2
输入: "AC"
输出: 29
1.在草稿纸上算一算即可得到规律。
2.大写字母的ASCII值-对应的列号=64,利用这个公式即可判断每个单一字母对应的列号。
3.将字母看做个位、十位、百位·······,每向前增加一位,对应的列号会大幅增加。
4.以ZBC为例,对应列号=26^2(90-64)+26^1(90-64)+26^0*(90-64)。
package LintCode_Easy; public class _1348 { public static void main(String[] args) { String s = "ZBC"; int total = 0; //以ZBC为例,列号=26^2*(90-64)+26^1*(90-64)+26^0*(90-64) for(int i=s.length()-1,j=0;i>=0;i--,j++) //i控制循环次数,j控制幂次 total+=((int)s.charAt(i)-64)*Math.pow(26, j); //大写字母的ASCII值-对应的列号=64 System.out.println(total); } }
public class Solution { public int titleToNumber(String s) { int total = 0; for(int i=s.length()-1,j=0;i>=0;i--,j++) total+=((int)s.charAt(i)-64)*Math.pow(26, j); return total; } }
FoorryNox
lamictal the new viagra The study by Rauschning and Lindgren provided a detailed description of the association between this valve mechanism and flexion and extension movements of the knee 9, 10
Preliaf
viagra original pill On my right ovary, I had a 13mm and a 15mm
ewSROsBBc
does viagra help with ejaculation It is based on the principle that most individuals with tinnitus can better tolerate outside noise than they can their own inner head noise
Awjvnk
buy fenofibrate pills for sale oral fenofibrate 200mg purchase tricor generic
Mjdmew
how to get ketotifen without a prescription buy geodon 40mg online cheap tofranil 75mg generic
Mzhmvr
cialis 40mg brand tadalafil 5mg oral sildenafil over counter
Clntcg
acarbose 50mg us order generic fulvicin 250mg order griseofulvin 250 mg
Ixvfkv
mintop canada tamsulosin brand ed pills that work