mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 21:24:53 +08:00
Fix two_sum.js and .ts
This commit is contained in:
@ -24,10 +24,10 @@ function twoSumHashTable(nums, target) {
|
||||
let m = {};
|
||||
// 单层循环,时间复杂度 O(n)
|
||||
for (let i = 0; i < nums.length; i++) {
|
||||
if (m[nums[i]] !== undefined) {
|
||||
return [m[nums[i]], i];
|
||||
if (m[target - nums[i]] !== undefined) {
|
||||
return [m[target-nums[i]], i];
|
||||
} else {
|
||||
m[target - nums[i]] = i;
|
||||
m[nums[i]] = i;
|
||||
}
|
||||
}
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user