94. 二叉树的中序遍历

题目链接:https://leetcode-cn.com/problems/binary-tree-inorder-traversal/

执行用时:0 ms, 在所有 Swift 提交中击败了100.00%的用户
内存消耗:13.6 MB, 在所有 Swift 提交中击败了44.81%的用户

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
var res: [Int] = []
func inorderTraversal(_ root: TreeNode?) -> [Int] {
guard let node = root else {
return []
}
inorderTraversal(node.left)
res.append(node.val)
inorderTraversal(node.right)
return res
}
}

94. 二叉树的中序遍历
https://pisces34.github.io/2021/09/28/leetcode/94/
发布于
2021年9月28日
许可协议