@@ -0,0 +1,1675 @@
+/**%0A *%09Implement atoi to convert a string to an integer.%0A *%0A *%09Hint: Carefully consider all possible input cases. %0A *%09If you want a challenge, please do not see below and ask yourself what are the possible input cases.%0A *%0A *%09Notes: It is intended for this problem to be specified vaguely (ie, no given input specs). %0A *%0A *%09You are responsible to gather all the input requirements up front.%0A *%0A *%09Author: matao%0A *%0A */%0A%0Apublic class StringToInteger %7B%0A%09/**%0A%09 *%09%E6%B3%A8%E6%84%8F%E8%B6%85%E8%BF%87%E6%9C%80%E5%A4%A7%EF%BC%8C%E6%9C%80%E5%B0%8F%E5%80%BC%EF%BC%8C%E8%BE%93%E5%85%A5%E5%B8%A6%E4%BA%86%E6%AD%A3%E8%B4%9F%E5%8F%B7%EF%BC%8C%E9%9D%9E%E6%B3%95%E8%BE%93%E5%85%A5%E7%AD%89%E6%83%85%E5%86%B5%E7%9A%84%E5%A4%84%E7%90%86%0A%09 *%0A%09 */%0A%09public static int myAtoi(String str) %7B%0A        if(str == null)%0A        %09return 0;%0A        str = str.trim();%0A        if(str.length() == 0)%0A        %09return 0;%0A        int sign = 1;%0A        int index = 0;%0A        if(str.charAt(index) == '+') %7B%0A        %09index++;%0A        %7D else if (str.charAt(index) == '-') %7B%0A        %09index++;%0A        %09sign = -1;%0A        %7D%0A        long result = 0;%0A        while(index %3C str.length()) %7B%0A        %09if(str.charAt(index) %3C '0' %7C%7C str.charAt(index) %3E '9')%0A        %09%09break;%0A        %09result = result * 10 + str.charAt(index) - '0';%0A        %09if (result %3E Integer.MAX_VALUE)%0A        %09%09break;%0A        %09index++;%0A        %7D%0A        if(sign * result %3E Integer.MAX_VALUE) %0A        %09return Integer.MAX_VALUE;%0A        if(sign * result %3C Integer.MIN_VALUE) %0A        %09return Integer.MIN_VALUE;%0A        return (int)(sign * result);%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A    %09System.out.println(myAtoi(%22123%22));%0A    %09System.out.println(myAtoi(%22+123%22));%0A    %09System.out.println(myAtoi(%22-123%22));%0A    %09System.out.println(myAtoi(%22-1123456765436765432%22));%0A    %09System.out.println(myAtoi(%229223372036854775809%22));%0A    %09System.out.println(myAtoi(%22safd%22));%0A    %7D%0A%7D

add String to Integer solution