Description:
Solution:
serialize()
if node is None --> append('n')
if node exist --> append(str(node.val))
We should search from left!
','.join(res) => ['a', 'b', 'c'] --> "a,b,c"
deserialize()
data.split(",") => "a,b,c" --> ['a', 'b', 'c']
self.i is the global variable
'n' means null, so return null. Don't forgetself.i += 1
We are gonna append TreeNode object. '(val)' is the string form, so we should change the type int.
Don't forget, do left first.
After loop, we are gonna return dfs().
'LeetCode ๐๏ธ > Tree' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
235. Lowest Common Ancestor of a Binary Search Tree (0) | 2023.06.09 |
---|---|
230. Kth Smallest Element in a BST (0) | 2023.06.05 |
98. Validate Binary Search Tree (0) | 2023.06.03 |
105. Construct Binary Tree from Preorder and Inorder Traversal (0) | 2023.06.02 |
572. Subtree of Another Tree (0) | 2023.04.02 |