File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ Constraints:
3
+ - 1 <= nums.length <= 10^4
4
+ - 0 <= nums[i] <= 10^5
5
+
6
+ Time Complexity: O(n)
7
+ - n์ ๋ฐฐ์ด์ ๊ธธ์ด๋งํผ ํ ๋ฒ ์ํ
8
+
9
+ Space Complexity: O(1)
10
+ - ์ถ๊ฐ ๊ณต๊ฐ ์ฌ์ฉ ์์
11
+
12
+ ํ์ด๋ฐฉ๋ฒ:
13
+ 1. max_reach ๋ณ์๋ก ํ์ฌ๊น์ง ๋๋ฌ ๊ฐ๋ฅํ ์ต๋ ๊ฑฐ๋ฆฌ ์ ์ฅ
14
+ 2. ๋ฐฐ์ด์ ์ํํ๋ฉด์:
15
+ - ํ์ฌ ์์น๊ฐ max_reach๋ณด๋ค ํฌ๋ฉด ๋๋ฌ ๋ถ๊ฐ๋ฅ
16
+ - max_reach๋ฅผ ํ์ฌ ์์น์์ ์ ํ ๊ฐ๋ฅํ ๊ฑฐ๋ฆฌ์ ๋น๊ตํด ์
๋ฐ์ดํธ
17
+ - max_reach๊ฐ ๋ง์ง๋ง ์ธ๋ฑ์ค๋ณด๋ค ํฌ๋ฉด ๋๋ฌ ๊ฐ๋ฅ
18
+ """
19
+ class Solution :
20
+ def canJump (self , nums : List [int ]) -> bool :
21
+ max_reach = nums [0 ]
22
+
23
+ for i in range (len (nums )):
24
+ if i > max_reach :
25
+ return False
26
+
27
+ max_reach = max (max_reach , i + nums [i ])
28
+
29
+ if max_reach >= len (nums ) - 1 :
30
+ return True
31
+
32
+ return True
You canโt perform that action at this time.
0 commit comments