572.Subtree-of-Another-Tree
572. Subtree of Another Tree
้ข็ฎๅฐๅ
https://leetcode.com/problems/subtree-of-another-tree/
้ข็ฎๆ่ฟฐ
ไปฃ็
Approach 1:
Approach #2: By Comparison of Nodes
1ใ้ๅฝๆณ่ชๅบๅไธTraverse
2ใๆฏๅฑTraverseไธญ๏ผeuqalsๅฝๅ่็นๅผไปฅๅๅทฆๅณๅญ่็นๆฏๅฆ็ธๅ
3ใๆฏๅฑTraverse้ฝไผ่ฟๅไธไธชequals
Complexity Analysis
Time complexity :O(_mโn). In worst case(skewed tree)
traverse
function takes _O(mโn) time.Space complexity : O(_n). The depth of the recursion tree can go upto n. _n refers to the number of nodes in s.
Last updated
Was this helpful?