File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 22
33
44class Solution :
5- def twoSum (self , nums : List [int ], target : int ) -> List [int ]:
5+ """
6+ Ideation:
7+ target = x + y -> target - x = y
8+ x ์์๋ฅผ ๊ฐ์ฅ ๋ฐ๊นฅ์ ์ดํฐ๋ ์ด์
์์ ๋๋ฉด์ ํ๋์ฉ ๋์
ํฉ๋๋ค.
9+ ์ฐพ๊ณ ์ ํ๋ ๊ฐ์ด (x,y) ์์ด๋ฏ๋ก, ๋๊ฐ์ ์ธ๋ฑ์ค๋ฅผ ์ฐพ๊ธฐ ์ํด ์ธ๋ฑ์ค ๊ธฐ์ค์ผ๋ก ์ดํฐ๋ ์ด์
์ ์ํํฉ๋๋ค( enumerate ์ฌ์ฉ ๊ฐ๋ฅ).
10+ y๊ฐ์ด ์ฐพ์์ง๋ฉด ๋น์์ x๊ฐ์ ์ธ๋ฑ์ค์ ํจ๊ป (index_of_x, index_of_y) ๋ฅผ ๋ฆฌ์คํธ๋ก ๋ฐํํฉ๋๋ค.
11+ Time Complexity: O(N^2)
12+ Space Complexity: O(1)
13+ """
614
15+ def twoSum (self , nums : List [int ], target : int ) -> List [int ]:
716 for i in range (0 , len (nums ) - 1 ):
817 for j in range (i + 1 , len (nums )):
918 if (target - nums [i ]) == nums [j ]:
You canโt perform that action at this time.
0 commit comments