Skip to content

Commit 4b9a4e3

Browse files
committed
Create: 0001-two-sum.dart
1 parent ed984b5 commit 4b9a4e3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

dart/0001-two-sum.dart

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Time Complexity: O(n)
2+
// Space Complexity: O(n)
3+
4+
class Solution {
5+
List<int> twoSum(List<int> nums, int target) {
6+
var map = Map<int, int>();
7+
for (int i = 0; i < nums.length; i++) {
8+
var x = target - nums[i];
9+
if (map.containsKey(x)) return [map[x]!, i];
10+
map[nums[i]] = i;
11+
}
12+
throw "";
13+
}
14+
}

0 commit comments

Comments
 (0)