class Solution {
public:
int maxProfit(vector<int>& prices) {
int result=0;
for(int i=1;i<prices.size();i++)
{
result+=max(prices[i]-prices[i-1],0);
}
return result;
}
};
class Solution {
public:
bool canJump(vector<int>& nums) {
int cover=0;
for(int i=0;i<=cover;i++)
{
cover=max(i+nums[i],cover);
if(cover>=nums.size()-1) return true;
}
return false;
}
};
class Solution {
public:
int jump(vector<int>& nums) {
if(nums.size()==1) return 0;
int curDistance=0;
int ans=0;
int nextDistance=0;
for(int i=0;i<nums.size();i++)
{
nextDistance=max(i+nums[i],nextDistance);
if(i==curDistance)
{
if(curDistance<nums.size()-1)
{
ans++;
curDistance=nextDistance;
if(nextDistance>=nums.size()-1) break;
}
else break;
}
}
return ans;
}
};