File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed
search-in-rotated-sorted-array Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change 11"""
22https://leetcode.com/problems/search-in-rotated-sorted-array/solutions/
33
4- ๋ฌธ์ : ํ์ ๋ ์ค๋ฆ์ฐจ์ ์ ๋ ฌ๋ ๋ฐฐ์ด nums์์ target ๊ฐ์ ์ธ๋ฑ์ค๋ฅผ ๋ฐํํ๋ผ.
5-
6- Idea: ์ด์ง ํ์ ํจํด ์ฌ์ฉ
4+ - in โ ๋ฆฌ์คํธ ์ ์ฒด๋ฅผ ์ ํ ํ์ (O(N))
5+ - index โ ๋ค์ ์ฒ์๋ถํฐ ์ ํ ํ์ (O(N))
76
8- TC: O(logN)
7+ Brute Force
8+ TC: O(N)
99SC: O(1)
1010"""
1111
1212from typing import List
1313
14+
15+ class Solution :
16+ def search (self , nums : List [int ], target : int ) -> int :
17+ if target in nums :
18+ return nums .index (target )
19+ else :
20+ return - 1
21+
22+ """
23+ ๋ฌธ์ : ํ์ ๋ ์ค๋ฆ์ฐจ์ ์ ๋ ฌ๋ ๋ฐฐ์ด nums์์ target ๊ฐ์ ์ธ๋ฑ์ค๋ฅผ ๋ฐํํ๋ผ.
24+
25+ Idea: ์ด์ง ํ์ ํจํด ์ฌ์ฉ
26+
27+
28+ TC: O(logN), while ๋ฃจํ์์ ๋งค๋ฒ ์ ๋ฐ์ฉ ์ค
29+ SC: O(1)
30+ """
1431class Solution :
1532 def search (self , nums : List [int ], target : int ) -> int :
1633 left , right = 0 , len (nums ) - 1
You canโt perform that action at this time.
0 commit comments