LeetCode-8.字符串转换整数(atoi)

LeetCode-8.字符串转换整数(atoi)_第1张图片

地址:https://leetcode-cn.com/problems/string-to-integer-atoi/

思路:按照题目要求判断即可

Code:

#include
using namespace std;
typedef long long LL;

class Solution {
public:
    int myAtoi(string str) {
        long long res=0;
        int l=0,len=str.length();
        while(l='0'&&str[l]<='9'){
				res=res*10+str[l++]-'0';
				if(p*resMax){
					res=Max;	break;
				}
			}
			res*=p;
		}
        return res;
    }
};

int main()
{
	ios::sync_with_stdio(false);
	string str;
	Solution So;
	cin>>str;
	cout<

 

你可能感兴趣的:(LeetCode,LeetCode)