LEETCODE 171
来源:互联网 发布:两个淘宝店铺怎么关联 编辑:程序博客网 时间:2024/05/16 11:59
Related to question Excel Sheet Column Title
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
本题类似于10进制的数字串计算整数,比如给定一个字符串“123456789”,那么思路肯定就是:
令SUM = 0;
当取出第i个数字时:有
sum = sum * 10 + a[i] - '0';
而现在类似的,只是进制不同,变成了26,同时不可能有0的出现,即出现的A应该代表1而不代表0.
class Solution {public: int titleToNumber(string s) { int sum = 0;for (int i = 0; i < s.length(); ++i)sum = sum * 26 + s[i] - 'A' + 1;return sum; }};
0 0
- LEETCODE 171
- Leetcode 171
- leetcode 171
- LeetCode 171 JAVA
- LeetCode Everyday --171
- Leetcode no. 171
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- MATLAB取整函数
- 解决 android studio .9图报错
- Git 笔记
- Android WebView+JSON+JavaScript
- maven项目管理
- LEETCODE 171
- advanced topics(重要的话题)
- oracle查询序列也会使得序列自增
- swift 的 JSON很麻烦
- Spring注入集合的值List,Set,Map,Properties
- TextView显示人民币符号¥
- codeforces 630K Indivisibility
- Android Volley 基本用法及解析
- Material Design之水波纹效果