摘要: ## 题目:[102. 二叉树的层序遍历](https://leetcode.cn/problems/binary-tree-level-order-traversal/) ### 思路: 先把根放进去,然后每次都是左右就可以了。 记录一个深度,当`len(res) == deepth`的时候就说明 阅读全文
posted @ 2023-08-09 20:36 WtcSky 阅读(18) 评论(0) 推荐(0)
摘要: 今天的题目就是二叉树的前中后序遍历,目前只写了递归方法,之后再补迭代方法。 ## 题目:[144. 二叉树的前序遍历](https://leetcode.cn/problems/binary-tree-preorder-traversal/) ### 思路: 前序遍历:根-左-右 ### 代码1: 阅读全文
posted @ 2023-08-08 21:10 WtcSky 阅读(19) 评论(0) 推荐(0)
摘要: ## 题目:[239. 滑动窗口最大值](https://leetcode.cn/problems/sliding-window-maximum/) ### 思路: ![239.滑动窗口最大值.gif](https://s2.loli.net/2023/08/07/9ohI1LGQlZmMVjn.g 阅读全文
posted @ 2023-08-07 21:30 WtcSky 阅读(15) 评论(0) 推荐(0)
摘要: ## 题目:[20. 有效的括号](https://leetcode.cn/problems/valid-parentheses/) ### 思路: 很简单的一个栈的题目: 1. 如果是左括号就存 2. 如果是右括号就和栈顶的匹配 1. 匹配失败就返回false 2. 匹配成功就删除栈顶元素 3. 阅读全文
posted @ 2023-08-05 12:44 WtcSky 阅读(18) 评论(0) 推荐(0)
摘要: ## 题目:[232. 用栈实现队列](https://leetcode.cn/problems/implement-queue-using-stacks/) ### 思路: 因为go没有栈和队列的类型,直接自己写就行了。 比较简单的实现,具体看代码中的注释。 ### 代码: ```go type 阅读全文
posted @ 2023-08-04 21:10 WtcSky 阅读(10) 评论(0) 推荐(0)
摘要: ## 题目:[28. 找出字符串中第一个匹配项的下标](https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string/) ### 思路: 说白了就是匹配字符串,朴素就是暴力以每一个位置为起点都跑一遍。 阅读全文
posted @ 2023-08-03 20:58 WtcSky 阅读(16) 评论(0) 推荐(0)
摘要: ## 题目:[344. 反转字符串](https://leetcode.cn/problems/reverse-string/) ### 思路: 每次把最前面和最后面的交换位置即可 `strings`库里没有反转的方法 ——这个反转是之后几个题的一个基础 ### 代码: 双指针调换位置 ```go 阅读全文
posted @ 2023-08-02 23:15 WtcSky 阅读(25) 评论(0) 推荐(0)
摘要: ## 题目:[454. 四数相加 II](https://leetcode.cn/problems/4sum-ii/) ### 思路: 首先,因为下标不同,因此相同的序列可能会出现很多次。 A + B + C + D = 0,那么当知道保存了A+B的和之后,就看有没有A + B = 0 - C - 阅读全文
posted @ 2023-08-01 21:50 WtcSky 阅读(9) 评论(0) 推荐(0)
摘要: ## 题目:[242. 有效的字母异位词](https://leetcode.cn/problems/valid-anagram/) ### 思路: 很简单,就是看两个字符串每个字母出现的次数是不是相同的。 可以用两个数组来比较,也可以用一个数组比较。 ### 代码: 一个数组 ```go func 阅读全文
posted @ 2023-07-31 21:00 WtcSky 阅读(15) 评论(0) 推荐(0)
摘要: ## 题目:[24. 两两交换链表中的节点](https://leetcode.cn/problems/swap-nodes-in-pairs/) ### 思路: ![6](https://s2.loli.net/2023/07/29/haIsMPevD7OfEpK.png) 首先给他加一个虚拟头结 阅读全文
posted @ 2023-07-29 21:32 WtcSky 阅读(15) 评论(0) 推荐(0)