We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f291ae8 commit 6e87952Copy full SHA for 6e87952
โtwo-sum/seungseung88.jsโ
@@ -0,0 +1,14 @@
1
+const twoSum = (nums, target) => {
2
+ // ๋ฐฐ์ด์ ํ ๋ฒ ์ํ
3
+ for (let i = 0; i < nums.length; i += 1) {
4
+ // target์ซ์์์ ํ์ฌ ์ซ์๋ฅผ ๋บ ์ซ์๊ฐ ์กด์ฌํ๋์ง ํ์ธํ๋ค.
5
+ const targetIndex = nums.indexOf(target - nums[i]);
6
+ // targetIndex๊ฐ ์กด์ฌํ๊ณ (-1์ด ์๋), ํ์ฌ ์ซ์์ ๊ฐ์ ์ธ๋ฑ์ค ์ซ์๊ฐ ์๋๋ผ๋ฉด ๋ฐํํ๋ค.
7
+ if (targetIndex !== -1 && i !== targetIndex) {
8
+ return [i, targetIndex];
9
+ }
10
11
+};
12
+
13
+// ์๊ฐ ๋ณต์ก๋๋ O(n^2)
14
+// ๊ณต๊ฐ ๋ณต์ก๋๋ O(1)
0 commit comments