问题叙述性说明:
Implement atoi to convert a string to an integer.
解决问题的思路:
对于一个字符串,需要注意以下几点:
1、所有的空气过滤器在字符串的开头格字符;
2、注意数字字符前面的“+”和“-”字符。从而确定数字的正负号;
3、仅仅处理数字字符,一旦出现非数字字符。马上停止字符串处理,并返回已处理的结果;
4、返回结果时要注意数字越界的问题。不能大于最大值,不能小于最小值。
class Solution { public: int atoi(const char *str) { if (str == NULL) return 0; const char *pCur = str; long long result = 0; int flag = 0;/*表示该数是否为负值*/ while (*pCur == ' ' && *pCur != '