diff --git a/leetCode Solutions/Q45_JumpGame2/Q45_JumpGame2.cpp b/leetCode Solutions/Q45_JumpGame2/Q45_JumpGame2.cpp new file mode 100644 index 0000000..5b0e8a6 --- /dev/null +++ b/leetCode Solutions/Q45_JumpGame2/Q45_JumpGame2.cpp @@ -0,0 +1,20 @@ +class Solution { +public: + int jump(vector& 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]; + } +}; \ No newline at end of file