Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal ...
原题地址:https: oj.leetcode.com problems same tree 题意:判断两棵树是否是同一棵树。 解题思路:这题比较简单。用递归来做。首先判断两个根节点的值是否相同,如果相同,递归判断根的左右子树。 代码: ...
2014-05-23 10:51 0 3413 推荐指数:
Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal ...
Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally ...
原题地址:https://oj.leetcode.com/problems/symmetric-tree/ 题意:判断二叉树是否为对称的。 Given a binary tree, check whether it is a mirror of itself (ie, symmetric ...
原题地址:http://oj.leetcode.com/problems/balanced-binary-tree/ 题意:判断一颗二叉树是否是平衡二叉树。 解题思路:在这道题里,平衡二叉树的定义是二叉树的任意节点的两颗子树之间的高度差小于等于1。这实际上是AVL树的定义。首先要写一个计算 ...
原题地址:http://oj.leetcode.com/problems/binary-tree-level-order-traversal/ 题意:二叉树的层序遍历的实现。 解题思路:二叉树的层序遍历可以用bfs或者dfs来实现。这里使用的dfs实现,代码比较简洁。实际上,二叉树的先序遍历 ...
原题地址:http://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ 题意: Given a binary tree, find its minimum depth. The minimum depth ...
原题地址:https://oj.leetcode.com/problems/maximum-depth-of-binary-tree/ 题意: Given a binary tree, find its maximum depth. The maximum depth ...
原题地址:https://oj.leetcode.com/problems/recover-binary-search-tree/ 题意: Two elements of a binary search tree (BST) are swapped by mistake. Recover ...