Two sum exercise

Run Settings
LanguageDart
Language Version
Run Command
void main() { //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. print('Hello World!'); class Solution { List<int> twoSum(List<int> nums, int target) { List <int> indicesArray = []; Map map = {}; for(var i = 0; i < nums.length; i ++){ if( map.containsKey(nums[i])){ indicesArray.addAll([map[nums[i]], i]); print(indicesArray); } map[target- nums[i]] = i; } return indicesArray; } } }
Editor Settings
Theme
Key bindings
Full width
Lines