/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/funcinorderTraversal(root*TreeNode)[]int{varres[]intvarinorderfunc(root*TreeNode)inorder=func(root*TreeNode){ifroot==nil{return}inorder(root.Left)res=append(res,root.Val)inorder(root.Right)}inorder(root)returnres}
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/funcinorderTraversal(root*TreeNode)[]int{varstack[]*TreeNodevarresult[]intforlen(stack)>0||root!=nil{forroot!=nil{stack=append(stack,root)root=root.Left}root=stack[len(stack)-1]stack=stack[:len(stack)-1]result=append(result,root.Val)root=root.Right}returnresult}