上一页 1 2 3 4 5 6 7 ··· 10 下一页
摘要: 437 路径总和||| 我的解法如下,但复杂度很高,想想也知道应该不是好的解法。。。 class Solution { int sum; LinkedList<Integer> list; int result; public int pathSum(TreeNode root, int sum) 阅读全文
posted @ 2021-02-25 09:23 雨落寒沙 阅读(147) 评论(0) 推荐(0)
摘要: 116 填充每个节点的下一个右侧节点 这个题如果没有空间复杂度要求可以如下 Map<Integer,Node> map; public Node connect(Node root) { map = new HashMap<>(); fill(root,1); return root; } publ 阅读全文
posted @ 2021-02-25 09:20 雨落寒沙 阅读(87) 评论(0) 推荐(0)
摘要: 897 递增顺序查找树 老实说这题自己都不知道怎么做出来的。。然后写完提交然后成功了。。然后看自己写的东西看了好一会儿才明白。。汗。。做的头有点晕 class Solution { public TreeNode increasingBST(TreeNode root) { if (root==nu 阅读全文
posted @ 2021-02-23 14:13 雨落寒沙 阅读(122) 评论(0) 推荐(0)
摘要: 404 按理说也可以递归做。 public static int sumOfLeftLeaves(TreeNode root) { int total = 0; LinkedList<TreeNode> stack = new LinkedList<>(); stack.push(root); wh 阅读全文
posted @ 2021-02-22 13:54 雨落寒沙 阅读(51) 评论(0) 推荐(0)
摘要: 397 核心思想应该是尽量减少奇数操作 public static int integerReplacement(int n) { if (n == Integer.MAX_VALUE){ return 0; } int k = 0; int result = 0; while (n !=1){ S 阅读全文
posted @ 2021-02-20 14:28 雨落寒沙 阅读(283) 评论(0) 推荐(0)
摘要: 78 下面是我的写法 应该比较啰嗦 public static List<List<Integer>> subsets(int[] nums) { List<List<Integer>> result = new ArrayList<>(); for (int i = 0; i < nums.len 阅读全文
posted @ 2021-02-19 10:34 雨落寒沙 阅读(61) 评论(0) 推荐(0)
摘要: 169 这算是个经典的问题了 不讲码德可以这样做 时间复杂度(nlogn) public int majorityElement(int[] nums) { Arrays.sort(nums); return nums[nums.length/2]; } 但是题目要求O(n)时间复杂度和O1空间复杂 阅读全文
posted @ 2021-02-08 13:50 雨落寒沙 阅读(148) 评论(0) 推荐(0)
摘要: 44 情侣牵手 硬写,居然通过了。。 public static int minSwapsCouples(int[] row) { Map<Integer,Integer> map = new HashMap<>(); for (int i = 0; i < row.length; i++) { m 阅读全文
posted @ 2021-02-07 11:50 雨落寒沙 阅读(86) 评论(0) 推荐(0)
摘要: 55 这题感觉自己犯蠢了 看了下评论恍然大悟、、 public boolean canJump(int[] nums) { int len = nums.length; if (len <= 1) return true; int maxDis = nums[0]; for (int i = 1; 阅读全文
posted @ 2021-02-05 14:08 雨落寒沙 阅读(96) 评论(0) 推荐(0)
摘要: 122 其实更简单的做法是只要是前一个数字比后一个大就相加 public static int maxProfit(int[] prices) { int min = prices[0]; int max = prices[0]; int total = 0; for (int i = 1; i < 阅读全文
posted @ 2021-02-03 17:23 雨落寒沙 阅读(81) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 ··· 10 下一页