
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
LeetCode kullanmaya yeni başladım. Hiçbir yardım almadan bunu çözmem 2 saat sürdü
Java:
class Solution {
public boolean canJump(int[] nums) {
int currentIndex = 0;
int furthestPossible;
boolean canReach = true;
while(currentIndex < (nums.length-1)){
furthestPossible = nums[currentIndex];
if(furthestPossible == 0){
canReach = false;
break;
}
for(int i = 1; i < nums[currentIndex] && (currentIndex + i) < nums.length; i++){
if(furthestPossible < nums[currentIndex+i]+i){
for(int j = nums[currentIndex+i]+i; j > furthestPossible; j--){
if(j+currentIndex < nums.length-1){
if(nums[currentIndex+j] != 0){
furthestPossible = j;
break;
}
}
else{
furthestPossible = j;
break;
}
}
}
}
currentIndex += furthestPossible;
}
return canReach;
}
}