diff --git a/src/main/java/com/cool/hot100/greedy/Num55.java b/src/main/java/com/cool/hot100/greedy/Num55.java new file mode 100644 index 0000000..d5dc8f7 --- /dev/null +++ b/src/main/java/com/cool/hot100/greedy/Num55.java @@ -0,0 +1,42 @@ +package com.cool.hot100.greedy; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/09/22/19:47 + * DayNumber 1 + * Hard 2 + * Level 5 + */ +public class Num55 { + public boolean canJump(int[] nums) { + int len=nums.length; + int maxDistance=0; + for(int i=0;i=len-1){ + return true; + } + } + } + return false; + } + + /** + * @Author Cool + * @Date 20:01 2024/9/22 + * 倒序遍历版 + **/ + public boolean canJump1(int[] nums) { + int step = 1; + for (int i = nums.length - 2; i > -1; i--) { + if (nums[i] >= step) { + step = 0; + } + step++; + } + return step == 1; + } +}