/twosum

small module that return indices of the two numbers in an array of numbers such that they add up to target

Primary LanguageTypeScript

Two sum leetcode solution with o(n) time complexity package

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

Install

npm install @adnen/twosum

Test

npm run test

Usage

// TYPESCRIPT FILE 
import twoSum from '@adnen/twosum'


const nums   : number[]   = [1,2,7,11,15];
const target : number     = 9;

const result : number[][] = twosum(nums,target)

console.log(result)
//  [[1,2]]
// JAVASCRIPT FILE 
import twoSum from '@adnen/twosum'


const nums   = [1,2,7,11,15];
const target = 9;

const result = twosum(nums,target)

console.log(result)
//  [[1,2]]