摘要: 题目:513. 找树左下角的值 题目链接:https://leetcode.cn/problems/find-bottom-left-tree-value/description/ 思路:理解题目最大深度,最左侧结点的值 遍历规则:采用深度优先遍历(DFS)+ 先左后右的顺序,优先遍历左子树再遍历右 阅读全文
posted @ 2026-02-02 21:38 whq001 阅读(3) 评论(0) 推荐(0)
摘要: 题目:平衡二叉树 题目链接:https://leetcode.cn/problems/balanced-binary-tree/solutions/377216/ping-heng-er-cha-shu-by-leetcode-solution/ 思路:平衡二叉树的定义是:二叉树的每个节点的左右子树 阅读全文
posted @ 2026-01-28 21:37 whq001 阅读(6) 评论(0) 推荐(0)
摘要: 题目:226. 翻转二叉树 题目链接:https://leetcode.cn/problems/invert-binary-tree/ 思路:1. 确定终止条件 root==null 2. 每次都交换左右两个子树 3. 递归传递的参数(左子树或右子树) 代码: 点击查看代码 public TreeN 阅读全文
posted @ 2026-01-27 20:53 whq001 阅读(3) 评论(0) 推荐(0)
摘要: 题目:144. 二叉树的前序遍历 题目链接:https://leetcode.cn/problems/binary-tree-preorder-traversal/description/ 思路:1. 确定终止条件 2. 确定执行一次递归的函数过程 3. 确定参数及返回值 代码: 点击查看代码 pu 阅读全文
posted @ 2026-01-26 21:49 whq001 阅读(2) 评论(0) 推荐(0)
摘要: 题目:232. 用栈实现队列 题目链接:https://leetcode.cn/problems/implement-queue-using-stacks/description/ 思路:定义两个栈,一个作为出栈,一个作为入栈。 代码: 点击查看代码 class MyQueue { Deque<In 阅读全文
posted @ 2026-01-25 18:21 whq001 阅读(4) 评论(0) 推荐(0)
摘要: 题目:151. 反转字符串中的单词 题目链接:https://leetcode.cn/problems/reverse-words-in-a-string/description/ 思路:1. 去除字符串的首尾空格,中间保留一个空格 2. 整个字符串全部反转 3. 根据空格,反转字符串中的单个单词 阅读全文
posted @ 2026-01-22 21:31 whq001 阅读(1) 评论(0) 推荐(0)
摘要: 题目:344. 反转字符串 题目链接:https://leetcode.cn/problems/reverse-string/description/ 思路:就是将字符数组中的元素交换位置(从中间分开),例子:第1个后最后一个交换,第2个和倒数第二个交换 代码: 点击查看代码 public void 阅读全文
posted @ 2026-01-21 20:40 whq001 阅读(2) 评论(0) 推荐(0)
摘要: 454. 四数相加 II 题目链接:https://leetcode.cn/problems/4sum-ii/description/ 思路:第一步:遍历nums1和nums2,统计「两数之和」的出现次数,存入哈希表map(键 = 两数之和,值 = 该和出现的次数); 第二步:遍历nums3和num 阅读全文
posted @ 2026-01-20 21:07 whq001 阅读(5) 评论(0) 推荐(0)
摘要: 题目:有效的字母异位词 代码链接:https://leetcode.cn/problems/valid-anagram/solutions/6690/hua-jie-suan-fa-242-you-xiao-de-zi-mu-yi-wei-ci-by/ 思路: 两个字符串由完全相同的英文字母组成,每 阅读全文
posted @ 2026-01-19 20:47 whq001 阅读(3) 评论(0) 推荐(0)
摘要: 两两交换链表中的节点 题目链接:https://leetcode.cn/problems/swap-nodes-in-pairs/solutions/444474/liang-liang-jiao-huan-lian-biao-zhong-de-jie-di-91/ 思路:新建头结点,保存第1结点, 阅读全文
posted @ 2026-01-18 19:13 whq001 阅读(3) 评论(0) 推荐(0)