From ffea6e1b4d216271d985f09643d25371365ffffc Mon Sep 17 00:00:00 2001 From: rrbharath Date: Tue, 28 Jul 2026 17:13:20 -0400 Subject: [PATCH] Add Dart solution for Two Sum --- dart/two_sum.dart | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 dart/two_sum.dart diff --git a/dart/two_sum.dart b/dart/two_sum.dart new file mode 100644 index 0000000..d5c6346 --- /dev/null +++ b/dart/two_sum.dart @@ -0,0 +1,22 @@ +/* +Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. + +You may assume that each input would have exactly one solution, and you may not use the same element twice. +*/ + +class Solution { + List twoSum(List nums, int target) { + final Map seen = {}; + + for (int i = 0; i < nums.length; i++) { + final int complement = target - nums[i]; + if (seen.containsKey(complement)) { + return [seen[complement]!, i]; + } + + seen[nums[i]] = i; + } + + return []; + } +}