We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6623491 commit cf996faCopy full SHA for cf996fa
Day-17/q3: Jump Game/Tech-neophyte--cp.md
@@ -0,0 +1,32 @@
1
+# Cpp Code
2
+<br /> 1. Update the variable maxreach with the next highest integer. It is the highest index it can jump upto at that point.
3
+<br /> 2. If index is greater than the index it can reach upto, return false.
4
+
5
+```
6
+class Solution {
7
+public:
8
+ bool canJump(vector<int>& nums) {
9
+ int n = nums.size();
10
+ int maxReach = 0;
11
+ for (int i = 0; i < n; i++) {
12
+ if (i > maxReach) return false;
13
+ maxReach = max(maxReach, i + nums[i]);
14
+ }
15
+ return true;
16
+}
17
+};
18
19
+# Python Code
20
21
+class Solution:
22
+ def canJump(self, nums: List[int]) -> bool:
23
+ jump = 0
24
+ for n in nums:
25
+ if jump < 0:
26
+ return False
27
+ elif n > jump:
28
+ jump = n
29
+ jump -= 1
30
31
+ return True
32
0 commit comments