Leetcode——171. Excel Sheet Column Number
2017-01-21 23:48
399 查看
题目
https://leetcode.com/problems/excel-sheet-column-number/解答
其实就是26进制转化为十进制class Solution { public: int titleToNumber(string s) { int res=0; for(int i=0;i<s.length();i++) { res=res*26+(s[i]-'A'+1); } return res; } };
相似题目:
class Solution { public: string convertToTitle(int n) { string res=""; while(n>0) { if(n%26==0) { res="Z"+res; n=n/26-1; } else { res= (char)(n%26+'A'-1)+res; n=n/26; } } return res; } };
Or
string convertToTitle(int n) { string ans; while (n) { ans = char ((n - 1) % 26 + 'A') + ans; n = (n - 1) / 26; } return ans; }
相关文章推荐
- leetcode 171-Excel Sheet Column Number
- LeetCode 171: Excel Sheet Column Number
- LeetCode171——Excel Sheet Column Number
- leetcode171 Excel Sheet Column Number
- 171. Excel Sheet Column Number Leetcode Python
- leetcode_171题——Excel Sheet Column Number(简单数学题)
- LeetCode 171. Excel Sheet Column Number
- Java for LeetCode 171 Excel Sheet Column Number
- leetcode[171]:Excel Sheet Column Number
- leetcode 171: Excel Sheet Column Number
- LeetCode 171 Excel Sheet Column Number
- LeetCode 171. Excel Sheet Column Number
- Leetcode 171 Excel Sheet Column Number
- [Leetcode 171, Easy]Excel Sheet Column Number
- [leetcode]C语言:171 Excel Sheet Column Number
- [LeetCode]171.Excel Sheet Column Number
- leetcode--171 Excel Sheet Column Number
- [LeetCode]171 Excel Sheet Column Number
- LeetCode(171) Excel Sheet Column Number
- leetcode[171] Excel Sheet Column Number