摘要: 1、leetcode1005 K次取反后最大化的数组和 思路 局部最优:让绝对值大的负数变为正数,当前数值达到最大,整体最优:整个数组和达到最大。 代码 class Solution { //共使用两次排序 public int largestSumAfterKNegations(int[] num 阅读全文
posted @ 2023-02-17 00:04 黄三七 阅读(28) 评论(0) 推荐(0)
摘要: 1、leetcode122 买卖股票的最佳时机Ⅱ 思路 局部最优:收集每天的正利润,全局最优:求得最大利润。通过局部最优推出全局最优 代码 class Solution { int maxBenefit = 0; public int maxProfit(int[] prices) { for(in 阅读全文
posted @ 2023-02-15 22:52 黄三七 阅读(17) 评论(0) 推荐(0)
摘要: 1、leetcode455 分发饼干 class Solution { public int findContentChildren(int[] g, int[] s) { Arrays.sort(g); Arrays.sort(s); int gIndex = 0; int sIndex = 0; 阅读全文
posted @ 2023-02-14 22:46 黄三七 阅读(16) 评论(0) 推荐(0)
摘要: 1、leetcode93 复原IP地址 class Solution { List<String> res = new ArrayList<>(); public boolean isValid(String s, int start, int end) { if(start > end) { re 阅读全文
posted @ 2023-02-14 22:40 黄三七 阅读(17) 评论(0) 推荐(0)
摘要: 1、leetcode39 组合总和 class Solution { List<Integer> path = new LinkedList<Integer>(); List<List<Integer>> res = new ArrayList<>(); int sum; public void b 阅读全文
posted @ 2023-02-13 23:57 黄三七 阅读(20) 评论(0) 推荐(0)
摘要: 1、leetcode216 组合总和Ⅲ class Solution { List<Integer> path = new LinkedList<Integer>();// 符合条件的结果 List<List<Integer>> res = new ArrayList<>();// 存放结果集 in 阅读全文
posted @ 2023-02-13 23:57 黄三七 阅读(24) 评论(0) 推荐(0)
摘要: 1、leetcode77 组合 class Solution { List<Integer> path = new LinkedList<Integer>();// 用来存放符合条件结果 List<List<Integer>> res = new ArrayList<>();// 存放符合条件结果的 阅读全文
posted @ 2023-02-13 23:55 黄三七 阅读(13) 评论(0) 推荐(0)
摘要: 1、669 修剪二叉搜索树 class Solution { public TreeNode trimBST(TreeNode root, int low, int high) { if(root == null){ return null; } if(root.val < low){ return 阅读全文
posted @ 2023-02-06 23:24 黄三七 阅读(19) 评论(0) 推荐(0)
摘要: 1、235. 二叉搜索树的最近公共祖先 class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if(root.val > p.val && root.val > q 阅读全文
posted @ 2023-02-05 19:12 黄三七 阅读(30) 评论(0) 推荐(0)
摘要: 1、530.二叉搜索树的最小绝对差 class Solution { private int res = Integer.MAX_VALUE; private TreeNode pre; public void traversal(TreeNode node) { if(node == null) 阅读全文
posted @ 2023-02-04 21:29 黄三七 阅读(32) 评论(0) 推荐(0)