From e847d49cefc9a49b392dcf55a438ef06c4c647cf Mon Sep 17 00:00:00 2001 From: rrbharath Date: Tue, 28 Jul 2026 17:15:06 -0400 Subject: [PATCH] Add Dart solution for Binary Tree Inorder Traversal --- dart/binary_tree_inorder_traversal.dart | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 dart/binary_tree_inorder_traversal.dart 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); + } +}