Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

617. 合并二叉树 #87

Open
Open
Labels
@Geekhyt

Description

@Geekhyt

原题链接

dfs 递归

在 root1 上直接修改,将两个树对应的节点相加后,赋值给 root1,然后递归执行两个左右子树。

constmergeTrees=function(root1,root2){constpreOrder=function(root1,root2){if(!root1)returnroot2if(!root2)returnroot1root1.val+=root2.valroot1.left=preOrder(root1.left,root2.left)root1.right=preOrder(root1.right,root2.right)returnroot1}returnpreOrder(root1,root2)}
  • 时间复杂度: O(min(m,n))
  • 空间复杂度: O(min(m,n))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp