Skip to content

剑指offer 18 题。 #3

@xuan25575

Description

@xuan25575

题目:输入两棵二叉树 A 和 B,判断 B 是不是 A 的子结构。
【解1】:

  •  利用二叉树的神级遍历(空间复杂度:O(1), 时间复杂度:O(h))
    
  •  转化成字符串匹配问题:KMP算法(时间:O(N))
    
  •  总的时间复杂度:O(N)
    

看起来是一种解 有bug 如果通过先序遍历不能够确定一个树把。就是说加入两棵树结构不一样,也能返回相同字符串吧。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions