public static boolean canJump2(int[] A) {//AC after consulting
    	if (A.length <= 1) return true;
    	if (A[0] > A.length-1) return true;
    	int maxlength = A[0];
    	if (maxlength == 0) return false;
    	for (int i = 1; i < A.length; ++i) {
    		if (maxlength >= i && i + A[i] >= A.length-1){
    			return true;
    		}
    		else if (maxlength <= i && A[i] == 0) {
    			return false;
    		}
    		else {
    			if (i + A[i] > maxlength) maxlength = i + A[i];
    		}
    	}
    	return false;
    }