- Notifications
You must be signed in to change notification settings - Fork24
Open
Labels
Description
递归 dfs
constserialize=function(root){constres=[]functiondfs(node){if(node===null){res.push(null)return}res.push(node.val)dfs(node.left)dfs(node.right)}dfs(root)returnres}
- 时间复杂度: O(n)
- 空间复杂度: O(n)
constdeserialize=function(data){functiondfs(){if(data.length===0)returnnullletval=data.shift()if(val===null)returnnullletnode=newTreeNode(val)node.left=dfs()node.right=dfs()returnnode}returndfs()}
- 时间复杂度: O(n)
- 空间复杂度: O(n)