We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
https://leetcode-cn.com/problems/jump-game/
The text was updated successfully, but these errors were encountered:
Sorry, something went wrong.
var canJump = function(nums) { return canJumpFromPos(0, nums); }; function canJumpFromPos(pos, nums) { if (pos === nums.length - 1) { return true; } let furtherJump = Math.min(pos + nums[pos], nums.length - 1); for (let nextPos = furtherJump; nextPos > pos; nextPos --) { if (canJumpFromPos(nextPos, nums)) { return true; } } return false; }
时间复杂度为什么是 O(2^n)
var canJump = function(nums) { const memo = new Array(nums.length); for (let i = 0; i < memo.length; i ++) { memo[i] = 'unkonwn'; } memo[memo.length - 1] = 'good'; const canJumpFromPos = (pos, nums) => { if (memo[pos] !== 'unkonwn') { return memo[pos] === 'good' ? true : false; } let furtherJump = Math.min(pos + nums[pos], nums.length - 1); for (let nextPos = furtherJump; nextPos > pos; nextPos --) { if (canJumpFromPos(nextPos, nums)) { memo[pos] = 'good'; return true; } } memo[pos] = 'bad'; return false; } return canJumpFromPos(0, nums); };
时间复杂度 O(n^2)
No branches or pull requests
https://leetcode-cn.com/problems/jump-game/
The text was updated successfully, but these errors were encountered: