Skip to content

Commit

Permalink
Merge pull request #39 from rakshitgondwal/rakshit5
Browse files Browse the repository at this point in the history
Added solution to Q45 in cpp
  • Loading branch information
DugarRishab authored Oct 3, 2022
2 parents 9b736a0 + 0b98cb4 commit 4694339
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions leetCode Solutions/Q45_JumpGame2/Q45_JumpGame2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution {
public:
int jump(vector<int>& nums) {
// support variables
int len = nums.size(), steps[len];
// presetting steps
for (int i = 1; i < len; i++) {
steps[i] = INT_MAX;
}
steps[0] = 0;
// populating steps with the lowest possible values
for (int i = 0; i < len; i++) {
for (int lmt = i, j = min(len - 1, i + nums[i]); j > lmt; j--) {
if (steps[j] > steps[i] + 1) steps[j] = steps[i] + 1;
else break;
}
}
return steps[len - 1];
}
};

0 comments on commit 4694339

Please sign in to comment.