LeetCode 1. Two Sum JavaScript

Gary Huang
Dublin so code
Published in
Apr 7, 2022
吃啦哪次不吃 XD

你領500元現金了嗎? 點選我的連結成功開樂天帳戶+登入樂天網銀APP,拿500元現金! 樂天帳戶好康在這 : · 使用行動支付5次,享次月活儲年息1.35%存額無上限 · VIP享每月免費跨提/轉共16次 · 提領日幣手續費優惠8次/月 (推薦序號: JGONGL)

var twoSum = function(nums, target) {
const handler = nums.reduce((acc, curr, index) => {
if (acc.hashMap.has(curr)) {
acc.result = [acc.hashMap.get(curr), index]
} else {
const sum = target - curr
acc.hashMap.set(sum, index)
}
return acc
}, {
hashMap: new Map(),
result: []
})

return handler.result
};
美國拉斯維加斯 羚羊谷 馬蹄灣 賭城 USA — Las Vegas / FunkyGary / edamame — bbno$

--

--

Gary Huang
Dublin so code

Self-taught in programming, currently working as a web developer and also a online course instructor, helping self-taught programmers find employment.