auto size = nums.size();
if (size == 1)
return 0;
int ans = 1, end = nums[0], far = nums[0];
for (int i = 0; i < nums.size() - 1; i++)
{
far = max(far, nums[i] + i);
if (i == end)
{
ans++;
end = far;
if (end >= size - 1)
break;
}
}
return ans;
'코딩테스트 > LeetCode' 카테고리의 다른 글
[LeetCode] 151. Reverse Words in a String (0) | 2024.07.02 |
---|---|
[LeetCode] 55. Jump Game (0) | 2024.06.17 |
[LeetCode] 136. Single Number (0) | 2024.06.13 |
[LeetCode] 1 - Two Sum (0) | 2024.04.03 |
[LeetCode] 6 - Zigzag Conversion (0) | 2024.04.03 |