public static int atoi2(String str) {
		// Note: The Solution object is instantiated only once and is reused by each test case.
		int result=0;
		for(int i=str.length()-1, w=0;i>=0;--i) {
			if(str.charAt(i)=='-') return -result;
			if(str.charAt(i)=='+') return result;
			if(str.charAt(i)!=' ') {
				result += ((int)(str.charAt(i))-48)*Math.pow(10,w);
				w++;
			}
		}
		return result;
	}