Thursday, January 29, 2015

Jump Game I LeetCode

public boolean canJump(int[] A) {
        // Note: The Solution object is instantiated only once and is reused by each test case.
        int coverage = 0;
        for (int i=0; i<=coverage && i<A.length; i++) {
            coverage = Math.max(coverage, A[i] + i);
        }
        return coverage >= A.length - 1;
    }

No comments:

Post a Comment