• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ying_vincent
博客园    首页    新随笔    联系   管理    订阅  订阅

LeetCode: Jump Game

少了一个 =, 两次过

 1 class Solution {
 2 public:
 3     bool canJump(int A[], int n) {
 4         // Start typing your C/C++ solution below
 5         // DO NOT write int main() function
 6         if (!n) return true;
 7         int left = 0;
 8         int right = A[0];
 9         while (left <= right) {
10             if (right >= n-1) return true;
11             right = max(right, left+A[left]);
12             left++;
13         }
14         return false;
15     }
16 };

 C#

 1 public class Solution {
 2     public bool CanJump(int[] nums) {
 3         if (nums.Length == 0) return true;
 4         int left = 0;
 5         int right = nums[0];
 6         while (left <= right) {
 7             if (right >= nums.Length - 1) return true;
 8             right = Math.Max(right, left + nums[left]);
 9             left++;
10         }
11         return false;
12     }
13 }
View Code

 

posted @ 2013-04-01 15:51  ying_vincent  阅读(152)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3