Skip to content

Commit

Permalink
added solution to q45
Browse files Browse the repository at this point in the history
  • Loading branch information
rakshitgondwal committed Oct 3, 2022
1 parent b037ba1 commit 0b98cb4
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 0b98cb4

Please sign in to comment.