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 eec10a2 commit d3ce1d4Copy full SHA for d3ce1d4
โtwo-sum/socow.pyโ
@@ -0,0 +1,16 @@
1
+# 1. ์ผ๋จ ๋์ ๋๋ฆฌ(num_map)๋ฅผ ๋ง๋ค์ด์ ์ซ์๋ ์ธ๋ฑ์ค๋ฅผ ์ ์ฅํ๋ค.
2
+# 2. ํ์ฌ ์ซ์์ target์ ๋บ ๊ฒฐ๊ณผ(๋ณด์ถฉ๊ฐ, complement)๋ฅผ ๊ณ์ฐํ๋ค.
3
+# 3. ๊ทธ complement๊ฐ ์ด๋ฏธ ๋์ ๋๋ฆฌ์ ์๋ค๋ฉด?
4
+# โ ๊ทธ ์ซ์์ ํ์ฌ ์ซ์๊ฐ ํฉ์ณ์ target์ด ๋๋ค๋ ๋ป!
5
+# 4. ์๋ค๋ฉด ํ์ฌ ์ซ์๋ฅผ ๋์ ๋๋ฆฌ์ ์ ์ฅํด์ ๋ค์์ ๋๋นํ๋ค.
6
+class Solution:
7
+ def twoSum(self, nums: List[int], target: int) -> List[int]:
8
+ num_map = {}
9
+
10
+ for i, num in enumerate(nums):
11
+ complement = target - num
12
13
+ if complement in num_map:
14
+ return [num_map[complement], i]
15
16
+ num_map[num] = i
0 commit comments