I don't think the official answer is correct. Below is the test case and my solution. Thanks.

Input:

"2147483648"

Output:

0

Expected:

2147483647

```
public class Solution {
public int myAtoi(String str) {
if (str == null || str.isEmpty()) return 0;
boolean positive = true;
int i = 0;
long rt = 0;
while (str.charAt(i) == ' ') i++;
if (str.charAt(i) == '-') {
positive = false;
i++;
} else if (str.charAt(i) == '+') i++;
for (; i < str.length(); i++) {
if (str.charAt(i) >= '0' && str.charAt(i) <= '9') {
rt = rt * 10 + str.charAt(i) - '0';
if (positive && rt > Integer.MAX_VALUE || !positive && -rt < Integer.MIN_VALUE) return 0;
} else {
return (int) (positive ? rt : -rt);
}
}
return (int) (positive ? rt : -rt);
}
}
```