What is Nostr?
dave /
npub1tsg…htk4
2023-02-08 05:11:25
in reply to nevent1q…28kk

dave on Nostr: // 后序遍历 func PostorderTraversal(root *TreeNode) []int { res := []int{} ...

// 后序遍历
func PostorderTraversal(root *TreeNode) []int {
res := []int{}
rootNode := root
stack := []*TreeNode{}
for rootNode != nil || len(stack) > 0 {
for rootNode != nil {
stack = append(stack, rootNode)
rootNode = rootNode.Left
}
if len(stack) > 0 {
rootNode = stack[len(stack)-1]
stack = stack[:len(stack)-1]
res = append(res, rootNode.Val)
rootNode = rootNode.Right
}
}
return res
}
Author Public Key
npub1tsgw6pncspg4d5u778hk63s3pls70evs4czfsmx0fzap9xwt203qtkhtk4