diff --git a/src/main/java/com/cool/hot100/greedy/Num45.java b/src/main/java/com/cool/hot100/greedy/Num45.java new file mode 100644 index 0000000..567ed8b --- /dev/null +++ b/src/main/java/com/cool/hot100/greedy/Num45.java @@ -0,0 +1,32 @@ +package com.cool.hot100.greedy; + +import org.junit.Test; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/09/23/20:47 + * DayNumber 1 + * Hard 2 + * Level 6 + */ +public class Num45 { + public int jump(int[] nums) { + int end=0; + int maxDistance=0; + int res=0; + for(int i=0;i<nums.length-1;i++){ + maxDistance=Math.max(maxDistance,i+nums[i]); + if(i==end){ + end=maxDistance; + res++; + } + } + return res; + } + @Test + public void test(){ + jump(new int[]{1,2,3,999}); + } +} diff --git a/src/main/java/com/cool/hot100/greedy/Num763.java b/src/main/java/com/cool/hot100/greedy/Num763.java new file mode 100644 index 0000000..0bafc25 --- /dev/null +++ b/src/main/java/com/cool/hot100/greedy/Num763.java @@ -0,0 +1,36 @@ +package com.cool.hot100.greedy; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/09/23/22:00 + * DayNumber 2 + * Hard 2 + * Level 4 + * Score 1443 + */ +public class Num763 { + + public List<Integer> partitionLabels(String s) { + int[] last = new int[26]; + for (int i = 0; i < s.length(); i++) { + last[s.charAt(i) - 'a'] = i; + } + int end=0; + int start=0; + List<Integer> res=new ArrayList<>(); + for (int i = 0; i < s.length(); i++) { + end=Math.max(end,last[s.charAt(i)-'a']); + if(end==i){ + res.add(end-start+1); + start=i+1; + } + } + return res; + } + +}