diff --git a/dart/binary_tree_inorder_traversal.dart b/dart/binary_tree_inorder_traversal.dart new file mode 100644 index 0000000..622eb80 --- /dev/null +++ b/dart/binary_tree_inorder_traversal.dart @@ -0,0 +1,31 @@ +/* +Given the root of a binary tree, return the inorder traversal of its nodes' values. +*/ + +/* +Definition for a binary tree node. +class TreeNode { + int val; + TreeNode? left; + TreeNode? right; + TreeNode([this.val = 0, this.left, this.right]); +} +*/ + +class Solution { + List inorderTraversal(TreeNode? root) { + final List ans = []; + inorder(root, ans); + return ans; + } + + void inorder(TreeNode? root, List ans) { + if (root == null) { + return; + } + + inorder(root.left, ans); + ans.add(root.val); + inorder(root.right, ans); + } +}