All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g2401_2500.s2498_frog_jump_ii.Solution Maven / Gradle / Ivy

There is a newer version: 1.35
Show newest version
package g2401_2500.s2498_frog_jump_ii;

// #Medium #Array #Greedy #Binary_Search #2023_02_12_Time_1_ms_(100.00%)_Space_55.8_MB_(66.50%)

public class Solution {
    public int maxJump(int[] stones) {
        int n = stones.length;
        int max = 0;
        for (int i = 2; i < n; i++) {
            int gap = stones[i] - stones[i - 2];
            if (gap > max) {
                max = gap;
            }
        }
        if (n > 2) {
            return max;
        } else {
            return stones[1] - stones[0];
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy