#先序遍历
class Solution:
def inorderTraversal(self, root: TreeNode) -> List[int]:
stack,res = [root],[]
while(stack):
h = stack.pop()
if h == None:continue
if isinstance(h,TreeNode):
stack += [h.right,h.left,h.val]
else:
res.append(h)
#中序遍历
class Solution:
def inorderTraversal(self, root: TreeNode) -> List[int]:
stack,res = [root],[]
while(stack):
h = stack.pop()
if h == None:continue
if isinstance(h,TreeNode):
stack += [h.right,h.val,h.left]
else:
res.append(h)
return res
#后序遍历
class Solution:
def inorderTraversal(self, root: TreeNode) -> List[int]:
stack,res = [root],[]
while(stack):
h = stack.pop()
if h == None:continue
if isinstance(h,TreeNode):
stack += [h.val,h.right,h.left]
else:
return res