Created
          February 22, 2022 07:32 
        
      - 
      
 - 
        
Save blessedjasonmwanza/8a632653c6918bbb260343f2c2cb704d to your computer and use it in GitHub Desktop.  
    Two Sum LeetCode Challenge
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // 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. | |
| // You can return the answer in any order. | |
| /** | |
| * @param {number[]} nums | |
| * @param {number} target | |
| * @return {number[]} | |
| */ | |
| var twoSum = function(nums, target) { | |
| for(let i = 0; i < nums.length; i +=1){ | |
| const posB = i + 1; | |
| if(nums[i] + nums[posB] === target){ | |
| return [i, posB]; | |
| } | |
| } | |
| }; | |
| console.log(twoSum([3,2,4, 1], 6)); | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment