publicclassSolution8{publicintmyAtoi(String str){if(str == null)return0;
str = str.trim();if(str.length()==0)return0;char c = str.charAt(0);boolean minus =false;if(c =='+')
str = str.substring(1);elseif(c =='-')
minus =true;elseif(c <'0'|| c >'9')return0;int ret =0;for(int i = minus ?1:0; i < str.length(); i++){
c = str.charAt(i);if(c <'0'|| c >'9')break;if(!minus &&(ret > Integer.MAX_VALUE /10|| ret == Integer.MAX_VALUE /10&& c >'7'))return Integer.MAX_VALUE;if(minus &&(ret >-(Integer.MIN_VALUE /10)|| ret ==-(Integer.MIN_VALUE /10)&& c >'8'))return Integer.MIN_VALUE;
ret *=10;
ret += c -'0';}return minus ?-ret : ret;}}