mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-25 14:46:28 +08:00
Add a test and update ts code style
This commit is contained in:
parent
3265e3fde0
commit
4a31f909c6
2 changed files with 19 additions and 10 deletions
|
@ -31,3 +31,12 @@ function twoSumHashTable(nums: number[], target: number): number[] {
|
|||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
/* Driver Code */
|
||||
let nums = [2, 7, 11, 15]
|
||||
twoSumBruteForce(nums, 9)
|
||||
console.log("使用暴力枚举后得到结果:", nums)
|
||||
|
||||
let nums1 = [2, 7, 11, 15]
|
||||
twoSumHashTable(nums1, 9)
|
||||
console.log("使用辅助哈希表后得到结果", nums1)
|
|
@ -102,7 +102,7 @@ comments: true
|
|||
for (let i = 0; i < n; i++) {
|
||||
for (let j = i + 1; j < n; j++) {
|
||||
if (nums[i] + nums[j] === target) {
|
||||
return [i, j]
|
||||
return [i, j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue