public class Solution {

```
public int myAtoi(String str) {
if(str == null || str.length() == 0)
return 0;
boolean isNegative = false;
str = str.trim();
if(str.charAt(0) == '-'){
isNegative = true;
}
str = str.replaceAll("[^\\d.]", "");
if(str.length() == 0)
return 0;
if(str.length() > 10){
if(!isNegative)
return Integer.MAX_VALUE;
return Integer.MIN_VALUE;
}
long num = Long.valueOf(str).longValue();
if(isNegative) num = -num;
if((int)num > Integer.MAX_VALUE){
return Integer.MAX_VALUE;
}
if((int)num < Integer.MIN_VALUE){
return Integer.MIN_VALUE;
}
return (int)num;
}
```

}