String to Integer (atoi)-LeetCode
来源:互联网 发布:淘宝王者荣耀点券 编辑:程序博客网 时间:2024/05/08 07:38
Implement atoi to convert a string to an integer.
Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.
class Solution {public: int atoi(const char *str) { long long num = 0; int sign = 1; const char *stemp = str; if (stemp == NULL) { return 0; } while(*stemp == ' ') { stemp++; } if (*stemp == '+') { stemp++; } else if (*stemp == '-') { sign = -1; stemp++; } while(*stemp == '0') { stemp++; } while (*stemp >= '0' && *stemp <= '9') { num = num * 10 + *stemp - '0'; if (num * sign > INT_MAX) return INT_MAX; if (num * sign < INT_MIN) return INT_MIN; stemp++; } return num * sign; }};
0 0
- LeetCode:String to Integer (atoi)
- LeetCode: String to Integer (atoi)
- LeetCode String to Integer(atoi)
- LeetCode :String to Integer (atoi)
- Leetcode: String to Integer (atoi)
- Leetcode : String to Integer (atoi)
- 【leetcode】String to Integer (atoi)
- [LeetCode]String to Integer (atoi)
- LeetCode-String to Integer (atoi)
- [leetcode] String to Integer (atoi)
- LeetCode - String to Integer (atoi)
- 【leetcode】String to Integer (atoi)
- LeetCode - String to Integer (atoi)
- LeetCode: String to Integer (atoi)
- Leetcode: String to Integer (atoi)
- [LeetCode] String to Integer (atoi)
- leetcode String to Integer (atoi)
- [LeetCode]String to Integer (atoi)
- 深入浅出API——Applicaiton源码分析
- 学习笔记--webview
- 修改label name后 linux无法启动
- java内存溢出分析
- Android 混淆打包详解
- String to Integer (atoi)-LeetCode
- findViewById的参数错误
- 20141022 N2
- 游戏任玩!开源虚拟现实头戴式设备Open DoVision
- php初学习一:数据库,文件,网络api基本函数
- c# Socket属性
- 部署出现“编译器失败,错误代码为:1073741819”
- 智力题总结
- Excel2003中两列对比,快速辨别相同与不同数据!