摘要:
222.完全二叉树的节点个数[https://leetcode.cn/problems/count-complete-tree-nodes/submissions/498293461/] 思路:递归法 class Solution { public int maxDepth(TreeNode roo 阅读全文
摘要:
226.翻转二叉树[https://leetcode.cn/problems/invert-binary-tree/description/] 递归:递归三部曲:①确定递归函数的参数和返回值 ②确定终止条件 ③确定单层递归的逻辑 /** * Definition for a binary tree 阅读全文
摘要:
144.二叉树的前序遍历[https://leetcode.cn/problems/binary-tree-preorder-traversal/] 思路:栈实现的迭代遍历:出栈记录,右孩子非空右孩子进栈,左孩子非空左孩子进栈。 /** * Definition for a binary tree 阅读全文
摘要:
344.翻转字符串[https://leetcode.cn/problems/reverse-string/submissions/496111203/] 思路:类似于原地翻转数组,左指针右指针向中间靠拢,交换对应元素。 class Solution { public void reverseStr 阅读全文
摘要:
383.赎金信https://leetcode.cn/problems/ransom-note/description/ 思路:本题与242.有效的字母异位词几乎相同。将字母-'a',变成0-26的数字存放于数组中,再遍历数组对比次数。 class Solution { public boolean 阅读全文