摘要:
1、leetcode1005 K次取反后最大化的数组和 思路 局部最优:让绝对值大的负数变为正数,当前数值达到最大,整体最优:整个数组和达到最大。 代码 class Solution { //共使用两次排序 public int largestSumAfterKNegations(int[] num 阅读全文
摘要:
1、leetcode122 买卖股票的最佳时机Ⅱ 思路 局部最优:收集每天的正利润,全局最优:求得最大利润。通过局部最优推出全局最优 代码 class Solution { int maxBenefit = 0; public int maxProfit(int[] prices) { for(in 阅读全文
摘要:
1、leetcode455 分发饼干 class Solution { public int findContentChildren(int[] g, int[] s) { Arrays.sort(g); Arrays.sort(s); int gIndex = 0; int sIndex = 0; 阅读全文
摘要:
1、leetcode93 复原IP地址 class Solution { List<String> res = new ArrayList<>(); public boolean isValid(String s, int start, int end) { if(start > end) { re 阅读全文
摘要:
1、leetcode39 组合总和 class Solution { List<Integer> path = new LinkedList<Integer>(); List<List<Integer>> res = new ArrayList<>(); int sum; public void b 阅读全文
摘要:
1、leetcode216 组合总和Ⅲ class Solution { List<Integer> path = new LinkedList<Integer>();// 符合条件的结果 List<List<Integer>> res = new ArrayList<>();// 存放结果集 in 阅读全文
摘要:
1、leetcode77 组合 class Solution { List<Integer> path = new LinkedList<Integer>();// 用来存放符合条件结果 List<List<Integer>> res = new ArrayList<>();// 存放符合条件结果的 阅读全文