File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution :
2+ def twoSum (self , nums : List [int ], target : int ) -> List [int ]:
3+ """
4+ Intuition:
5+ ๊ธฐ์กด์ ํ์๋ 3sum ๋ฌธ์ ์ ์ ์ฌํ๊ฒ,
6+ ํด์์ ํ์ฌ ์ซ์์ ๋ํด์ target์ด ๋๋ ๊ฐ์ ์ฐพ๋๋ค.
7+ ๋ง์ฝ ์์ ๊ฒฝ์ฐ, ํด์์ ํ์ฌ ๊ฐ๊ณผ ์ธ๋ฑ์ค๋ฅผ ์ ์ฅํ๋ค.
8+
9+ Time Complexity:
10+ O(N):
11+ ํด์๋ ์ ๊ทผํ๋ ๋ฐ์ O(1)์ด ์์๋๊ณ ,
12+ ์ด N๋ฒ ๋ฐ๋ณตํด์ผ ํ๋ฏ๋ก ์๊ฐ๋ณต์ก๋๋ O(N)์ด๋ค.
13+
14+ Space Complexity:
15+ O(N):
16+ ์ต์
์ ๊ฒฝ์ฐ ํด์์ N๊ฐ์ ์ซ์์ ์ธ๋ฑ์ค๋ฅผ ์ ์ฅํด์ผ ํ๋ค.
17+ """
18+ complement_dict = {}
19+ for i , num in enumerate (nums ):
20+ if target - num in complement_dict :
21+ return [complement_dict [target - num ], i ]
22+ else :
23+ complement_dict [num ] = i
You canโt perform that action at this time.
0 commit comments