摘要:
贪心 import java.util.Arrays; class Solution { public int largestSumAfterKNegations(int[] nums, int k) { /** * 先将数组排序,让负数在前面,然后只反转负数 */ Arrays.sort(nums 阅读全文
摘要:
贪心 class Solution { public int maxSubArray(int[] nums) { /** * 元素中有负数,因此max初始值取负数最小值 */ int max = -Integer.MAX_VALUE; int sum = 0; for (int i = 0; i < 阅读全文
摘要:
深度优先搜索 class Solution { public TreeNode trimBST(TreeNode root, int low, int high) { if (root == null){ return root; } /** * 如果根节点小于最小值,那其左子树肯定也小于最小值,那 阅读全文
摘要:
深度优先搜索 class Solution { public TreeNode insertIntoBST(TreeNode root, int val) { if (root == null){ return new TreeNode(val); } if (root.val > val){ ro 阅读全文