Find two numbers that sum up to 0
2022年5月1日小于 1 分钟
Find two numbers that sum up to 0
Question
Given an array of integers, find two number that sums up to 0, return their indices.
There might be multiple pairs, any of them would do. If not found, return null
findTwo([1,2,3,-1])
// [0,3]
findTwo([1,2,3,-1,-2,0])
// [0,3] or [1,4] or [5, 5]
findTwo([1,2,3,4])
// null
Code
/**
* @param {number[]} arr
* @return {number[]}
*/
function findTwo(arr) {
// your code here
}