public int atoi(String str) {
        long result  =0l;
        int ans = 1;
        String val = str.trim();
        int length = val.length();
        if(length == 0)
            return 0;
        int index = 0;
        if(val.charAt(index) == '+' || val.charAt(index) == '-'){
            ans = (val.charAt(index) == '-' ? -1 : 1);
            index++;
        }
        while(index < length && val.charAt(index) >= '0' && val.charAt(index) <= '9'){
            result = result * 10 + val.charAt(index) - '0';
            index++;
        }
        result = ans * result;
        if(result > 2147483647)
           return  2147483647;
        if(result < -2147483648)
            return  -2147483648;
        return (int)result;
    }