Skip to content

Commit ec0e51f

Browse files
Merge pull request #1939 from CodingTestStudy2/최민지
[최민지] Day32
2 parents 0bdafd8 + 0b2cbac commit ec0e51f

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎leetcode3/최민지/403.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)