From 5694c8e8ff684475d6c8b97accc24ff89091f15f Mon Sep 17 00:00:00 2001 From: gyt95 Date: Thu, 15 Dec 2022 23:41:06 +0800 Subject: [PATCH] update code style for js --- .../leetcode_two_sum.js | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/codes/javascript/chapter_computational_complexity/leetcode_two_sum.js b/codes/javascript/chapter_computational_complexity/leetcode_two_sum.js index 432e2b2ee..7629dd3c4 100644 --- a/codes/javascript/chapter_computational_complexity/leetcode_two_sum.js +++ b/codes/javascript/chapter_computational_complexity/leetcode_two_sum.js @@ -2,7 +2,7 @@ * @Author: gyt95 (gytkwan@gmail.com) * @Date: 2022-12-15 10:51:54 * @Last Modified by: gyt95 (gytkwan@gmail.com) - * @Last Modified time: 2022-12-15 10:56:26 + * @Last Modified time: 2022-12-15 23:40:09 */ /** @@ -11,26 +11,26 @@ * @return {number[]} */ function twoSumBruteForce(nums, target) { - let n = nums.length; - // 两层循环,时间复杂度 O(n^2) - for (let i = 0; i < n; i++) { - for (let j = i + 1; j < n; j++) { - if (nums[i] + nums[j] === target) { - return [i, j] - } + let n = nums.length; + // 两层循环,时间复杂度 O(n^2) + for (let i = 0; i < n; i++) { + for (let j = i + 1; j < n; j++) { + if (nums[i] + nums[j] === target) { + return [i, j]; + } + } } - } } function twoSumHashTable(nums, target) { - // 辅助哈希表,空间复杂度 O(n) - let m = {} - // 单层循环,时间复杂度 O(n) - for (let i = 0; i < nums.length; i++) { - if (m[nums[i]] !== undefined) { - return [m[nums[i]], i] - } else { - m[target - nums[i]] = i; + // 辅助哈希表,空间复杂度 O(n) + let m = {}; + // 单层循环,时间复杂度 O(n) + for (let i = 0; i < nums.length; i++) { + if (m[nums[i]] !== undefined) { + return [m[nums[i]], i]; + } else { + m[target - nums[i]] = i; + } } - } } \ No newline at end of file