@@ -0,0 +1,1309 @@
+package leetcode;%0A%0A/**%0A * https://oj.leetcode.com/problems/string-to-integer-atoi/%0A */%0Apublic class Problem8 %7B%0A    public int atoi(String str) %7B%0A        long result = 0;%0A        String trimmedStr = str.trim();%0A        if (trimmedStr.isEmpty()) %7B%0A            return (int) result;%0A        %7D%0A        boolean negative = false;%0A        int start = 0;%0A        if (trimmedStr.charAt(0) == '-') %7B%0A            negative = true;%0A            start = 1;%0A        %7D else if (trimmedStr.charAt(0) == '+') %7B%0A            start = 1;%0A        %7D%0A        int end = start;%0A        for (; end %3C trimmedStr.length(); end++) %7B%0A            char c = trimmedStr.charAt(end);%0A            if (c %3C 48 %7C%7C c %3E 57) %7B // 0 - 9%0A                break;%0A            %7D%0A        %7D%0A        int j = 0;%0A        // from the start to the end, there should only be numbers%0A        for (int i = end-1; i %3E= start; i--) %7B%0A            result += getNum(trimmedStr.charAt(i)) * Math.pow(10, j);%0A            j++;%0A        %7D%0A        if (negative) %7B%0A            result *= -1;%0A        %7D%0A        if (result %3E Integer.MAX_VALUE) %7B%0A            return Integer.MAX_VALUE;%0A        %7D else if (result %3C Integer.MIN_VALUE) %7B%0A            return Integer.MIN_VALUE;%0A        %7D%0A        return (int) result;%0A    %7D%0A    %0A    private int getNum(char c) %7B%0A        return c - 48; %0A    %7D%0A%7D%0A

Solve problem 8