摘要: 贪心 class Solution { public int monotoneIncreasingDigits(int n) { /** * 将数字拆分为字符数组 * start为第一个需要变为9的位置,后面的位置全部要变为9 */ char[] chars = String.valueOf(n). 阅读全文
posted @ 2022-02-26 21:50 振袖秋枫问红叶 阅读(37) 评论(0) 推荐(0)
摘要: 贪心 class Solution { public int wiggleMaxLength(int[] nums) { int prev = 0; int cur = 0; int count = 1; /** * 遍历时记录前一个差值和当前差值,如果差值正负交替,总数就加1,然后更新前一个差值 阅读全文
posted @ 2022-02-26 19:59 振袖秋枫问红叶 阅读(25) 评论(0) 推荐(0)
摘要: 贪心 import java.util.Arrays; import java.util.Comparator; import java.util.LinkedList; class Solution { public int[][] merge(int[][] intervals) { /** * 阅读全文
posted @ 2022-02-26 17:42 振袖秋枫问红叶 阅读(29) 评论(0) 推荐(0)
摘要: 贪心 import java.util.LinkedList; import java.util.List; class Solution { public List<Integer> partitionLabels(String s) { /** * 用哈希表记录每个字母出现的最后位置 */ in 阅读全文
posted @ 2022-02-26 17:17 振袖秋枫问红叶 阅读(48) 评论(0) 推荐(0)
摘要: 贪心 import java.util.Arrays; import java.util.Comparator; class Solution { public int eraseOverlapIntervals(int[][] intervals) { /** * 和《452. 用最少数量的箭引爆 阅读全文
posted @ 2022-02-26 15:59 振袖秋枫问红叶 阅读(27) 评论(0) 推荐(0)
摘要: 贪心 import java.util.Arrays; import java.util.Comparator; import java.util.LinkedList; class Solution { public int findMinArrowShots(int[][] points) { 阅读全文
posted @ 2022-02-26 15:35 振袖秋枫问红叶 阅读(33) 评论(0) 推荐(0)
摘要: 贪心 import java.util.Arrays; import java.util.Comparator; import java.util.LinkedList; class Solution { public int[][] reconstructQueue(int[][] people) 阅读全文
posted @ 2022-02-26 14:23 振袖秋枫问红叶 阅读(33) 评论(0) 推荐(0)
摘要: 贪心 class Solution { public boolean lemonadeChange(int[] bills) { int five = 0; int ten = 0; for (int i = 0; i < bills.length; i++) { if (bills[i] == 5 阅读全文
posted @ 2022-02-26 13:12 振袖秋枫问红叶 阅读(36) 评论(0) 推荐(0)
摘要: 贪心 import java.util.Arrays; class Solution { public int candy(int[] ratings) { /** * 初始每个孩子一颗糖 */ int[] res = new int[ratings.length]; Arrays.fill(res 阅读全文
posted @ 2022-02-26 12:22 振袖秋枫问红叶 阅读(35) 评论(0) 推荐(0)
摘要: 贪心 import java.util.Arrays; class Solution { public int canCompleteCircuit(int[] gas, int[] cost) { /** * 如果总的油量小于总的消耗量,那肯定无法跑一圈 */ if (Arrays.stream( 阅读全文
posted @ 2022-02-26 11:33 振袖秋枫问红叶 阅读(34) 评论(0) 推荐(0)