leetcode 100. Same Tree

題目:

Given two binary trees, write a function to check if they are equal or not.

Two binary trees are considered equal if they are structurally identical and the nodes have the same value.

判斷兩棵二叉樹是否相等,即結構相同,且對應的節點具有相同的值


思路:由樹的前序、中序和後序遍歷,想到用遞歸的方法,先判斷根節點是否相同,再依次判斷左子樹和右子樹是否相同。


代碼AC:


發佈了36 篇原創文章 · 獲贊 1 · 訪問量 9547
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章