摘要:
动态规划 class Solution { public int maxProfit(int[] prices, int fee) { int[][] dp = new int[prices.length][2]; dp[0][0] = -prices[0]; /** * 和《122. 买卖股票的最 阅读全文
摘要:
贪心 class Solution { public int wiggleMaxLength(int[] nums) { int prev = 0; int cur = 0; int count = 1; /** * 遍历时记录前一个差值和当前差值,如果差值正负交替,总数就加1,然后更新前一个差值 阅读全文
摘要:
贪心 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 阅读全文
摘要:
贪心 import java.util.Arrays; class Solution { public int candy(int[] ratings) { /** * 初始每个孩子一颗糖 */ int[] res = new int[ratings.length]; Arrays.fill(res 阅读全文