Medium
,Array
,Greedy
,Binary Search
You are given a 0-indexed integer array stones
sorted in strictly increasing order representing the positions of stones in a river.
A frog, initially on the first stone, wants to travel to the last stone and then return to the first stone. However, it can jump to any stone at most once.
The length of a jump is the absolute difference between the position of the stone the frog is currently on and the position of the stone to which the frog jumps.
stones[i]
and is jumping to stones[j]
, the length of the jump is |stones[i]
- stones[j]
|.The cost of a path is the maximum length of a jump among all jumps in the path.
Return the minimum cost of a path for the frog.
Example 1:
Example 2:
Constraints:
stones.length
<= 105stones[i]
<= 109stones[0]
== 0stones
is sorted in a strictly increasing order.Yen-Chi ChenMon, Dec 12, 2022
Yen-Chi ChenMon, Dec 12, 2022
吉神教學:
首先,跨三格沒意義,他會產生一個很大的步伐距離
所以問題就變成要走一步還兩步
然後,只要有走一步的,因為不能重複踩,回來時至少兩步以上
因此把所有兩步距離算出來找最大的就好感恩彥吉讚嘆彥吉
Marsgoat Dec 12, 2022