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 ...