leetcode 8. String to Integer (atoi)
来源:互联网 发布:linux创建新用户命令 编辑:程序博客网 时间:2024/06/03 15:14
class Solution {public: int myAtoi(string str) { string x = ""; int n = str.length(); int l=0,r=n-1; while(str[l]==' '&&l<n)l++; while(str[r]==' '&&r>0)r--; int be =0; if(str[l] == '+' || str[l] == '-') be=1; long long ans = 0; int flag = 1; if(str[l] == '-') flag = -1; for(int i = be+l;i <= r; i++){ if(str[i] < '0' || str[i] > '9') break; ans = ans*10+str[i]-'0'; if(ans > 2147483647 && flag == 1) return 2147483647; else if(ans > 2147483648 && flag == -1) return -2147483648; } return ans*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)
- MySQL语法(二 )--update--and 和 or--order by--delect(数据的操作)----drop(库的操作)
- 第十/十一周项目六-是春哥啊
- 求两个数的最大公约数
- 统一建模语言 UML
- 三层架构 mvc区别
- leetcode 8. String to Integer (atoi)
- 形状类族中的纯虚函数
- maomao
- jvm读书笔记-2.3内存对象的创建、布局和访问
- HDU2000
- OpenglES2.0 for Android:来画个立方体吧
- 第十四周阅读程序——2
- List在Python中的使用
- iOS多线程编程(一)——RunLoop基本概念