2 parents 0bdafd8 + 0b2cbac commit ec0e51fCopy full SHA for ec0e51f
1 file changed
leetcode3/최민지/403.py
@@ -0,0 +1,18 @@
1
+class Solution:
2
+ def canCross(self, stones: List[int]) -> bool:
3
+
4
+ if stones[1] != 1:
5
+ return False
6
7
+ dp = {stone: set() for stone in stones}
8
9
+ dp[0].add(0)
10
11
+ for stone in stones:
12
+ for k in dp[stone]:
13
+ for step in (k - 1, k, k + 1):
14
+ if step > 0 and (stone + step) in dp:
15
+ dp[stone + step].add(step)
16
17
+ return len(dp[stones[-1]]) > 0
18
0 commit comments