![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
codeTop
acmug
Go to bed early, get up early, knock code
展开
-
LeetCode4. 寻找两个正序数组的中位数
题目描述给定两个大小为 m 和 n 的正序(从小到大)数组 nums1 和 nums2。请你找出并返回这两个正序数组的中位数。进阶:你能设计一个时间复杂度为 O(log (m+n)) 的算法解决此问题吗?示例 1:输入:nums1 = [1,3], nums2 = [2]输出:2.00000解释:合并数组 = [1,2,3] ,中位数 2示例 2:输入:nums1 = [1,2], nums2 = [3,4]输出:2.50000解释:合并数组 = [1,2,3,4] ,中位数 (2 +原创 2020-12-10 09:35:06 · 137 阅读 · 0 评论 -
leetcode33
题目这道题主要就是需要观察规律,旋转数组一定存在左边是升序或者右边是升序的情况,根据该情况进行分类讨论即可第一步就是区分那一边的数组是升序还是无序class Solution { public int search(int[] nums, int target) { int left = 0; int right = nums.length - 1; while (left <= right) {原创 2022-04-27 14:34:11 · 144 阅读 · 0 评论 -
leetcode103
题目public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode() { } TreeNode(int val) { this.val = val; } TreeNode(int val, TreeNode left, TreeNode right) {原创 2022-04-26 20:48:36 · 67 阅读 · 0 评论 -
leetcode207
拓扑排序在图论中,拓扑排序(Topological Sorting)是一个有向无环图(DAG, Directed Acyclic Graph)的所有顶点的线性序列。且该序列必须满足下面两个条件:每个顶点出现且只出现一次。若存在一条从顶点 A 到顶点 B 的路径,那么在序列中顶点 A 出现在顶点 B 的前面。有向无环图(DAG)才有拓扑排序,非DAG图没有拓扑排序从 DAG 图中选择一个 没有前驱(即入度为0)的顶点并输出。从图中删除该顶点和所有以它为起点的有向边。重复 1 和 2 直到当前原创 2022-04-25 16:17:29 · 174 阅读 · 0 评论 -
leetcode146
codeTop题目public class LRUCache { class DLinkedNode { int key; int value; DLinkedNode prev; DLinkedNode next; public DLinkedNode() {} public DLinkedNode(int key, int value) { this.key = key原创 2021-05-23 11:03:39 · 46 阅读 · 0 评论 -
leetcode450
题目我的思路public TreeNode deleteNode(TreeNode root, int key) { if (root == null) { return null; } //创建一个临时节点,表示root的父节点,相当于preRoot值是Integer.MAX_VALUE // 目的是因为如果root节点是被删除节点,preRoot可以少很多判断。原创 2022-04-22 18:48:26 · 260 阅读 · 0 评论 -
leetcode124
题目考查递归我的思路第一次20分钟做出一道困难题。。private int max = Integer.MIN_VALUE; public int maxPathSum(TreeNode root) { if (root == null) { return 0; } dfs(root); return max; } public int dfs(TreeNode root) {原创 2022-04-21 11:22:24 · 89 阅读 · 0 评论 -
leetcode236
codeTop题目二叉树后序遍历public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if (root == null || root.val == p.val || root.val == q.val) { return root; } TreeNode left = lowestCommonAncestor(root.left原创 2022-04-20 18:27:25 · 379 阅读 · 0 评论