2 parents 42309aa + da61cbc commit 0bdafd8Copy full SHA for 0bdafd8
1 file changed
leetcode3/남효정/403. Frog Jump.py
@@ -0,0 +1,24 @@
1
+# 풀이 실패
2
+class Solution:
3
+ def canCross(self, stones: List[int]) -> bool:
4
+ # 첫 점프는 무조건 1칸이라 1번 돌 없으면 바로 실패임
5
+ if stones[1] != 1:
6
+ return False
7
+
8
+ # 각 돌 위치별 도달했던 점프 거리(k) 집합 초기화
9
+ jumps = {stone: set() for stone in stones}
10
+ jumps[0].add(0)
11
12
+ for stone in stones:
13
+ for k in jumps[stone]:
14
+ # 이동 가능한 다음 점프 거리 반복문
15
+ for step in (k - 1, k, k + 1):
16
+ next_pos = stone + step
17
+ if step > 0 and next_pos in jumps:
18
+ jumps[next_pos].add(step)
19
20
+ # 마지막 돌에 도달 기록 있으면 성공임
21
+ return len(jumps[stones[-1]]) > 0
22
23
24
0 commit comments