leetcode 8. String to Integer (atoi)
来源:互联网 发布:剑三萝莉捏脸数据2017 编辑:程序博客网 时间:2024/06/09 14:46
这个题目很奇怪,按理来说应该不难,但是有很多的特殊情况需要考虑,各种乱七八糟的特例。"+2","-156"," -9","+-2","-+3"等类似的情况,所以多错几次来试错还是有必要的。
class Solution {
public: int myAtoi(string str) { long result = 0; int flag = 1; for(int i = 0; i<str.size();) { i = str.find_first_not_of(' '); if(str[i] == '-' || str[i] == '+') flag = (str[i++] == '-')? -1 : 1; while('0'<= str[i] && str[i] <= '9') { result = result*10 + (str[i++]-'0'); if(result*indicator >= INT_MAX) return INT_MAX; if(result*indicator <= INT_MIN) return INT_MIN; } break; } return result*flag;}};
阅读全文
0 0
- [LeetCode]8. String to Integer (atoi)
- LeetCode 8. String to Integer (atoi)
- 8. String to Integer (atoi) Leetcode Python
- LeetCode --- 8. String to Integer (atoi)
- LeetCode 8.String to Integer (atoi)
- [Leetcode] 8. String to Integer (atoi)
- [leetcode] 8.String to Integer (atoi)
- [LeetCode] 8.String to Integer (atoi)
- <LeetCode OJ> 8. String to Integer (atoi)
- leetCode 8. String to Integer (atoi)
- 8. String to Integer (atoi) LeetCode
- leetcode 8. String to Integer (atoi)
- leetcode 8. String to Integer (atoi)
- LeetCode OJ 8.String to Integer (atoi)
- Leetcode ☞ 8. String to Integer (atoi)
- 8. String to Integer (atoi) ---Leetcode
- leetcode 8. String to Integer (atoi)
- Leetcode: 8. String to Integer (atoi)(JAVA)
- 用C语言打印杨辉三角
- 杨辉三角重要性质
- 读《中华文化十二讲》
- Linux Centos7-安装python3.5.2 pip setuptools
- sqoop使用hcatlog生成对应的orc格式的表
- leetcode 8. String to Integer (atoi)
- c/c++中的const
- Python爬虫之re库(一)----常用操作符
- HDOJ 1753 大明A+B(大数)
- Android视频硬解稳定性问题探讨和处理
- Java BigDecimal详解
- python 使用json模块
- C++数据结构双链表
- Codeforces Round #439 (Div. 2)(补题) A模拟+set B 数学 C dp or 杨辉三角组合数