LeetCode 8. String to Integer (atoi)
来源:互联网 发布:买家淘宝换名字怎么改 编辑:程序博客网 时间:2024/05/28 15:56
There are quite a lot of details to pay attentions to. But, the most important one is : watch out overflow..... Thus, the res value should be long long int type.
Better to compare with this question : http://blog.csdn.net/github_34333284/article/details/51171908
int myAtoi(string str) { if(str.size() == 0) return 0; int i = 0; long long int res = 0; bool negative = false; while(i < str.size() && str[i] == ' ') { i++; } if(str[i] == '-' || str[i] == '+') {str[i++] == '-' ? negative = true : negative = false;} while(i < str.size()) { if(str[i] >= '0' && str[i] <= '9') { res = res * 10 + (str[i] - '0'); if(res > INT_MAX) return negative ? INT_MIN : INT_MAX; } else {break;} i++; } return negative ? -1 * res : res; }
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)
- 基于Volley封装自己的简易网络框架
- JAVA 基础之集合专题
- JAVA 代理模式(Proxy)
- C或C++ 求两个数组相同元素个数
- 含有虚函数的类sizeof大小
- LeetCode 8. String to Integer (atoi)
- eclispe控制台输出太多前面的被掩盖,设置输出定向到一个文件,但是文件有时候内容不全问题解决
- 剑指offer面试题 赋值运算符函数
- 【bzoj2665】【CQOI2012】【编号】【dp】
- RxJava转换操作符
- kali无线网卡选购 无线技术概念
- 代理模式
- Ubuntu server 16.04LTS尝鲜之安装
- 数据结构与算法--顺序表