403. Frog Jump

A frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.
Given a list of stones' positions (in units) in sorted ascending order, determine if the frog is able to cross the river by landing on the last stone. Initially, the frog is on the first stone and assume the first jump must be 1 unit.
If the frog's last jump was k units, then its next jump must be either k - 1, k, or k + 1 units. Note that the frog can only jump in the forward direction.

Solution:DP

思路:

https://leetcode.com/problems/frog-jump/discuss/88824/Very-easy-to-understand-JAVA-solution-with-explanations

Time Complexity: O() Space Complexity: O()

Solution Code:


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...
    土汪阅读 14,353评论 0 33
  • “我了解他吧 他是那种宁愿自己哭死也不会来找我的那种” “那你把他的想法都想了”
    吹嫂阅读 1,235评论 0 0
  • 没有执行的想法只是幻觉 至少70%的人不配拥有梦想!梦想是人生奋斗的目标与灯塔,而他们只是看着梦想的灯塔发呆,他们...
    星云冰夜阅读 1,937评论 0 0
  • 引言Alphago打破围棋神话、无人驾驶、机器人送餐,人工智能已备受全球瞩目,现在资本的热潮也正转向AI市场,智能...
    UCloud云计算阅读 4,310评论 0 2
  • 今天是地推集训的第二天,早上吃过早饭,我们冒雨赶到公司,在会议室,谢工给我们讲解了山东有线app的使用方...
    臣舞阅读 7,313评论 0 0