Re: [闲聊] 每日leetcode

楼主: DJYOMIYAHINA (通通打死)   2024-07-17 10:43:10
肥肥今天又翘班打code了
希望老板不要把我sa了
def delNodes(self, root: Optional[TreeNode], to_delete: List[int]) ->
List[TreeNode]:
ans = []
if root.val not in to_delete:
ans.append(root)
def dfs(root):
nonlocal ans
if root is None:
return root
root.right = dfs(root.right)
root.left = dfs(root.left)
delete_cur = root.val in to_delete
if delete_cur:
if root.left:
ans.append(root.left)
if root.right:
ans.append(root.right)
return None if delete_cur else root
dfs(root)
return ans
作者: sustainer123 (caster)   2023-07-17 10:43:00
帮内推
作者: nozomizo (希霙)   2024-07-17 10:46:00
要去咕咕噜了

Links booklink

Contact Us: admin [ a t ] ucptt.com