- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cpp
More file actions
Latest commit
28 lines (28 loc) · 675 Bytes
/
Copy pathSolution.cpp
File metadata and controls
28 lines (28 loc) · 675 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
classSolution {
public:
intmyAtoi(string str) {
longlong res=0;
int sign=1;
int i=0;
for(;i<str.size();i++) {
if (str[i]!='') break;
}
if (str[i]=='-') {
sign=-1;
i++;
} elseif (str[i]=='+') {
i++;
}
for(;i<str.size();i++) {
auto c=str[i];
if (0<=c-'0' && c-'9'<=9) {
res=res*10 + (c-'0');
if (res*sign >= INT_MAX) returnINT_MAX;
if (res*sign <= INT_MIN) returnINT_MIN;
} else {
break;
}
}
return res*sign;
}
};