Given the root of a binary tree, return the inorder traversal of its nodes' values.

&nbsp;
Example 1:

Input: root = [1,null,2,3]
Output: [1,3,2]


Example 2:

Input: root = []
Output: []


Example 3:

Input: root = [1]
Output: [1]


&nbsp;
Constraints:


	The number of nodes in the tree is in the range [0, 100].
	-100 &lt;= Node.val &lt;= 100


&nbsp;
Follow up: Recursive solution is trivial, could you do it iteratively?
from typing import List, Optional


class Solution:
	"""
	Time:   O(n)
	"""

	def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
		inorder = []
		stack = []

		while stack or root is not None:
			if root:
				stack.append(root)
				root = root.left
			else:
				node = stack.pop()
				inorder.append(node.val)
				root = node.right

		return inorder


class Solution:
	"""
	Time:   O(n)
	"""

	def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
		return list(self.inorder_generator(root))

	@classmethod
	def inorder_generator(cls, tree: Optional[TreeNode]):
		if tree is not None:
			yield from cls.inorder_generator(tree.left)
			yield tree.val
			yield from cls.inorder_generator(tree.right)
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    List<Integer> li = new LinkedList<Integer>();
    public List<Integer> inorderTraversal(TreeNode root) {
     if(root == null){
         List<Integer> li = new LinkedList<Integer>();
         return li ;
     }
     inorderTraversal(root.left);     
     li.add(root.val);     
     inorderTraversal(root.right);
     return li;

    }
    
}
class Solution {
public:
    vector<int> v;
    vector<int> inorderTraversal(TreeNode* root) {
        if(root!=NULL){
            inorderTraversal(root->left);
            v.push_back(root->val);
            inorderTraversal(root->right);            
        }
        return v;
    }
};
var inorderTraversal = function(root) {
    let result = [];
    function traverse(node) {
        if(!node) {
            return;
        }
        traverse(node.left);
        result.push(node.val);
        traverse(node.right);
    }
    traverse(root);
    return result;
};
Binary Tree Inorder Traversal