finish: 94
This commit is contained in:
parent
c4ddb1d696
commit
d0349bbcf9
25
leetcode/94.py
Normal file
25
leetcode/94.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
|
||||||
|
# Definition for a binary tree node.
|
||||||
|
class TreeNode:
|
||||||
|
def __init__(self, val=0, left=None, right=None):
|
||||||
|
self.val = val
|
||||||
|
self.left = left
|
||||||
|
self.right = right
|
||||||
|
|
||||||
|
|
||||||
|
class Solution:
|
||||||
|
def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
|
||||||
|
if root is None:
|
||||||
|
return []
|
||||||
|
if root.left is not None:
|
||||||
|
return (
|
||||||
|
self.inorderTraversal(root.left)
|
||||||
|
+ [root.val]
|
||||||
|
+ self.inorderTraversal(root.right)
|
||||||
|
)
|
||||||
|
elif root.right is not None:
|
||||||
|
return [root.val] + self.inorderTraversal(root.right)
|
||||||
|
else:
|
||||||
|
return [root.val]
|
Loading…
x
Reference in New Issue
Block a user