Quick actions

cmd+k|ctrl+k

Navigation

Languages

Two sum exercise

Snippet info

Language

Dart

Visibility

public

Author

obihenry578

Created

2025-02-07T14:38:45.205357Z

Updated

2025-02-08T08:19:53.684106Z

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;
  
}
}
}
INFO