原文:[leetcode]Same Tree @ Python

原題地址:https: oj.leetcode.com problems same tree 題意:判斷兩棵樹是否是同一棵樹。 解題思路:這題比較簡單。用遞歸來做。首先判斷兩個根節點的值是否相同,如果相同,遞歸判斷根的左右子樹。 代碼: ...

2014-05-23 10:51 0 3413 推薦指數:

查看詳情

[LeetCode] 100. Same Tree 判斷相同樹

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

Mon Oct 27 15:54:00 CST 2014 5 10709
[leetcode]Symmetric Tree @ Python

原題地址:https://oj.leetcode.com/problems/symmetric-tree/ 題意:判斷二叉樹是否為對稱的。 Given a binary tree, check whether it is a mirror of itself (ie, symmetric ...

Fri May 23 19:03:00 CST 2014 0 4264
[leetcode]Balanced Binary Tree @ Python

原題地址:http://oj.leetcode.com/problems/balanced-binary-tree/ 題意:判斷一顆二叉樹是否是平衡二叉樹。 解題思路:在這道題里,平衡二叉樹的定義是二叉樹的任意節點的兩顆子樹之間的高度差小於等於1。這實際上是AVL樹的定義。首先要寫一個計算 ...

Sat May 10 18:54:00 CST 2014 0 5388
[leetcode]Binary Tree Level Order Traversal @ Python

原題地址:http://oj.leetcode.com/problems/binary-tree-level-order-traversal/ 題意:二叉樹的層序遍歷的實現。 解題思路:二叉樹的層序遍歷可以用bfs或者dfs來實現。這里使用的dfs實現,代碼比較簡潔。實際上,二叉樹的先序遍歷 ...

Mon May 12 01:55:00 CST 2014 0 4584
[leetcode]Minimum Depth of Binary Tree @ Python

原題地址:http://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ 題意: Given a binary tree, find its minimum depth. The minimum depth ...

Mon May 12 02:23:00 CST 2014 0 3285
[leetcode]Maximum Depth of Binary Tree @ Python

原題地址:https://oj.leetcode.com/problems/maximum-depth-of-binary-tree/ 題意: Given a binary tree, find its maximum depth. The maximum depth ...

Thu Jun 12 00:40:00 CST 2014 0 3260
[leetcode]Recover Binary Search Tree @ Python

原題地址:https://oj.leetcode.com/problems/recover-binary-search-tree/ 題意: Two elements of a binary search tree (BST) are swapped by mistake. Recover ...

Fri May 23 06:20:00 CST 2014 0 2850
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM