标签:tco string png images char color tom leetcode pad
----------------------------------
乘权相加即可。
AC代码:(从右往左)
public class Solution { public int titleToNumber(String s) { int res=0; for(int i=s.length()-1;i>=0;i--) res+=(s.charAt(i)-‘A‘+1)*((int)(Math.pow(26,s.length()-i-1))); return res; } }
精简版AC代码:(从左往右)
public class Solution { public int titleToNumber(String s) { int res=0; for(int i=0;i<s.length();i++) res=res*26+s.charAt(i)-‘A‘+1; return res; } }
题目来源: https://leetcode.com/problems/excel-sheet-column-number/
LeetCode之171. Excel Sheet Column Number
标签:tco string png images char color tom leetcode pad
原文地址:http://www.cnblogs.com/cc11001100/p/5998537.html