
贪心
我,秦始皇的爷爷,打钱
道阻且长,行则将至
展开
-
LeetCode刷题记206-greedy(贪心)
面试题 17.08. 马戏团人塔wo zhen de yu chun…class Solution { public int bestSeqAtIndex(int[] height, int[] weight) { if (height.length <= 1) return height.length; int[][] p = new int[height.length][2]; for (int i = 0; i < p.leng原创 2021-03-27 11:44:33 · 92 阅读 · 0 评论 -
LeetCode刷题记5-122. 买卖股票的最佳时机 II
LeetCode刷题记3122. 买卖股票的最佳时机 II题目典型的贪心题,比较简单,看了一下别人的解法,也差不多,下面贴自己的。class Solution { public int maxProfit(int[] prices) { int num = prices.length; int ans = 0, i = 0; while (i < num - 1) { if (prices[i] < pri原创 2020-11-08 20:44:48 · 95 阅读 · 0 评论 -
LeetCode刷题记159-1326. 灌溉花园的最少水龙头数目
LeetCode刷题记1591326. 灌溉花园的最少水龙头数目题目class Solution { public int minTaps(int n, int[] ranges) { if (n == 0) return 0; int[] sta = new int[n + 1]; // 记录有用的水龙头的下标 int sta_id = 0; // 有用的水龙头的最后一个 int end = 0; for原创 2020-12-23 15:08:44 · 329 阅读 · 0 评论 -
LeetCode刷题记158-1665. 完成所有任务的最少初始能量
LeetCode刷题记1581665. 完成所有任务的最少初始能量题目class Solution { public int minimumEffort(int[][] tasks) { // 直接数组排序快一点 Arrays.sort(tasks, new Comparator<int[]>() { @Override public int compare(int[] o1, int[] o2)原创 2020-12-22 15:26:03 · 210 阅读 · 1 评论 -
LeetCode刷题记157-927. 三等分
LeetCode刷题记157927. 三等分题目class Solution { public boolean equal(int[] sum_one, int i1, int j1, int i2, int j2, int i3, int j3) { if (i1 > j1 || i2 > j2 || i3 > j3) { return false; } if (sum_one[i1] - sum_o原创 2020-12-22 11:17:31 · 148 阅读 · 0 评论