deno.land / x / masx200_leetcode_test@10.6.5 / two-sum / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export default function two_Sum(nums: number[], target: number): number[] { const storeNumstoindex = new Map<number, number>();
for (const [i, num1] of nums.entries()) { const num2 = target - num1; const index2 = storeNumstoindex.get(num2); if (typeof index2 !== "undefined") { return [i, index2]; } else { storeNumstoindex.set(num1, i); } } throw Error("should not go here");}
masx200_leetcode_test

Version Info

Tagged at
a year ago