public class Solution {
    public static int StrToInt(String str) {
        char[] arr=str.toCharArray();
        if(arr.length==0){
            return 0;
        }
        int sum=0;
        int flag=1;
        if(arr[0]=='-'){
            flag=-1;
            arr[0]='0';
        }else if (arr[0] == '+'){
            flag=1;
            arr[0]='0';
        }
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] < '0' || arr[i] > '9') {
                sum = 0;
                break;
            }
            sum =sum*10+ (arr[i] - '0') ;
        }
        return flag*sum;
    }
}