-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8.cpp
More file actions
31 lines (31 loc) · 828 Bytes
/
8.cpp
File metadata and controls
31 lines (31 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Solution {
public:
int myAtoi(string str) {
int n = str.size()-1;
int i =0;
while(i<=n && str[i]==' ')
i++;
while(i<=n && str[n]==' ')
n--;
long long int res = 0;
int sign = 1;
if(i<=n){
if(str[i]=='+' || str[i]=='-'){
sign = (str[i]=='+')? 1:-1;
i++;
}
cout<<i <<" "<< n;
long long int curr = 0;
while(i<=n && isdigit(str[i])){
curr = curr*10 + (str[i++]-'0');
cout<<curr<<"\n";
if((curr*sign)>INT_MAX)
return INT_MAX;
if((curr*sign)<INT_MIN)
return INT_MIN;
}
res = sign*curr;
}
return res;
}
};