Leetcode刷题笔记
文章平均质量分 63
弗拉基米尔的镰刀
老大哥双加好
展开
-
二叉搜索树的第k大节点(二叉树的中序遍历)Leetcode 刷题日记 2021.2.25
Leetcode 刷题日记2021.2.25题目链接:https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/问题描述:给定一棵二叉搜索树,找出其中第k大的节点。解答:中序遍历的非递归实现代码:class Solution { public int kthLargest(TreeNode root, int k) { LinkedList<TreeNode>原创 2021-02-26 09:34:17 · 288 阅读 · 4 评论 -
递增顺序二叉查找树(树的中序遍历)Leetcode 刷题日记 2021.2.20
Leetcode 刷题日记2021.2.20题目链接:https://leetcode-cn.com/problems/increasing-order-search-tree/问题描述:按递增顺序把二叉查找树进行重新排列解答1:分治算法(本质是中序遍历的递归实现)代码:class Solution { public TreeNode increasingBST(TreeNode root) { TreeNode newRoot = root;原创 2021-02-20 15:44:11 · 504 阅读 · 6 评论 -
获取树的叶子节点:叶子相似的树 Leetcode 刷题日记 2021.2.19
Leetcode 刷题日记2021.2.19题目链接:https://leetcode-cn.com/problems/leaf-similar-trees/问题描述:解答1:非递归的深度优先代码:class Solution { public boolean leafSimilar(TreeNode root1, TreeNode root2) { LinkedList<TreeNode> leaves1= leaves(root1);原创 2021-02-19 17:10:19 · 182 阅读 · 0 评论 -
Leetcode 刷题日记 2021.2.15 平衡二叉树的判定
Leetcode 刷题日记2021.2.15题目链接:https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/submissions/问题描述:给出一棵树的根节点,判定这棵树是否为平衡二叉树解答1:递归+深度计算函数代码:public class Solution { public boolean isBalanced(TreeNode root) { if(root == null) return原创 2021-02-15 22:43:12 · 171 阅读 · 0 评论 -
Leetcode 刷题日记 2021.2.14 二叉树的深度
Leetcode 刷题日记2021.2.14题目链接:https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/submissions/问题描述:输入二叉树的根节点,返回其深度解答1:非递归深度优先搜索代码:public class Solution { public int maxDepth(TreeNode root) { if(root == null) return 0; //若原创 2021-02-14 18:58:56 · 207 阅读 · 0 评论 -
Leetcode 刷题日记 2021.2.12
Leetcode 刷题日记2021.2.3题目链接:https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/问题描述:计算斐波拉契数列任意一项模1000000007后的值解答1:递归代码:class Solution { public int fib(int n) { if(n == 1) return 0; else if(n == 2) return 1; else r原创 2021-02-12 21:02:59 · 161 阅读 · 0 评论 -
Leetcode 刷题日记 2021.2.8
Leetcode 刷题日记2021.2.8题目链接:问题描述:解答1:代码:分析:时间复杂度:O()空间复杂度:O()运行结果:评注:解答2:代码:分析:时间复杂度:O()空间复杂度:O()运行结果:评注:解答3:代码:分析:时间复杂度:O()空间复杂度:O()运行结果:评注:...原创 2021-02-09 12:32:00 · 213 阅读 · 0 评论 -
Leetcode 刷题日记 2021.2.7
Leetcode 刷题日记2021.2.7题目链接:https://leetcode-cn.com/problems/implement-stack-using-queues/submissions/问题描述:用队列实现栈解答1:双队列实现代码:import java.util.LinkedList;class MyStack { LinkedList<Integer> queue1 = new LinkedList<>(); LinkedL原创 2021-02-08 23:09:21 · 161 阅读 · 0 评论 -
Leetcode 刷题日记 2021.2.6(补充)
Leetcode 刷题日记2021.2.6(补充)题目链接:https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/solution/mian-shi-ti-09-yong-liang-ge-zhan-shi-xian-dui-l-3/问题描述:用两个栈实现队列解答1:用Stack实现代码:import java.util.Stack;class CQueue { Stack<原创 2021-02-07 17:53:01 · 179 阅读 · 0 评论 -
Leetcode 刷题日记 2021.2.6
Leetcode 刷题日记2021.2.6题目链接:https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/submissions/问题描述:实现一个栈,通过调用min()方法,查询栈中的最小元素,该方法的时间复杂度必须为O(1)解答1:栈(Stack)+有序表(SortedList)代码:import java.util.ArrayList;import java.util.Comparator;import原创 2021-02-06 22:15:20 · 215 阅读 · 1 评论 -
Leetcode 刷题日记 2021.2.3
Leetcode 刷题日记2021.2.3题目链接:https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/问题描述: 解答一:栈代码:class Solution { public ListNode reverseList(ListNode head) { Stack<ListNode> stack = new Stack(); while(head != null){原创 2021-02-06 13:25:02 · 233 阅读 · 2 评论