236. 二叉树的最近公共祖先java
class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if(root == null || p == root || q
Golang刷题Leetcode 100. Same Tree
最常见的解法就是递归codetypeTreeNodestruct{ValintLeft*TreeNodeRight*TreeNode}funcisSameTreebool{ifp==nil&&q==nil{returntrue}if||{returnfalse}ifp.Val!
2021-04-13:判断二叉树是否是平衡二叉树?
2021-04-13:判断二叉树是否是平衡二叉树?福大大 答案2021-04-13:1.左子节点平衡。 2.右子节点平衡。 3.左右子节点高度差不超过1。 采用递归即可。 代码用golang编写。
Golang刷题Leetcode 104. Maximum Depth of Binary Tree
找到二叉树的最大深度思路递归获得左右子树的深度,返回两个深度的最大值+1codetypeTreeNodestruct{ValintLeft*TreeNodeRight*TreeNode}funcmaxDepthint{ifroot==nil{return0}l:=maxDepth
Golang刷题Leetcode 114. Flatten Binary Tree to Linked List
题目:FlattenBinaryTreetoLinkedListGivenabinarytree,flattenittoalinkedlistin-place.把一颗二叉树展平成一个链表思路循环遍历左子树,不停的把左子树对接到右子树上去codetypeTreeNodestruct
Golang 刷题Leetcode 101. Symmetric Tree
判断一颗二叉树是否左右对称思路把一棵树当成两颗来处理,递归判断AB两棵树的左右子树是否对称相等codetypeTreeNodestruct{ValintLeft*TreeNodeRight*TreeNode}funcisSymmetricbool{returnisMirror}f