-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path008.cpp
40 lines (35 loc) · 799 Bytes
/
008.cpp
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
32
33
34
35
36
37
38
39
40
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
int myAtoi(string str) {
int n = 0;
int i = 0;
while (str[i] == ' ') {
i++;
}
int sign = 1;
if (str[i] == '+') {
i++;
} else if (str[i] == '-') {
sign = -1;
i++;
}
while(str[i] >= '0' and str[i] <= '9') {
int tmp = 10 * n + str[i] - '0';
if ((long)n * 10 + str[i] - '0' != (long)tmp) {
if (sign == 1) {
return INT_MAX;
} else {
return INT_MIN;
}
}
n = tmp;
i++;
}
return n * sign;
}
};
int main() {
return 0;
}