We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9e2277f commit ba3622dCopy full SHA for ba3622d
jump-game.cpp
@@ -0,0 +1,11 @@
1
+//Runtime: 13 ms
2
+class Solution {
3
+public:
4
+ bool canJump(vector<int>& nums) {
5
+ int j = 0;
6
+ for(int i=0;i<nums.size() && i<=j;i++){
7
+ j = max(j, i+nums[i]);
8
+ }
9
+ return j >= (nums.size()-1);
10
11
+};
jump-game.scala
@@ -0,0 +1,10 @@
+//Runtime: 392 ms
+object Solution {
+ def canJump(nums: Array[Int]): Boolean = {
+ nums.zipWithIndex
+ .foldLeft((0, 0))((a, b) =>
+ if (a._1 < b._2 + b._1 && b._2 <= a._2) (b._2 + b._1, b._2 + b._1)
+ else a)
+ ._1 >= (nums.size - 1)
+}
0 commit comments