【LeetCode】按摩师

按摩师

链接: 按摩师

题目描述

算法分析

编程代码

cpp 复制代码
class Solution {
public:
    int massage(vector<int>& nums) {
        int n = nums.size();
        if(n == 0) return 0;
        vector<int> f(n);
        auto g = f;
        f[0] = nums[0];
        for(int i = 1;i<n;i++)
        {
            f[i] = g[i-1] + nums[i];
            g[i] = max(f[i-1],g[i-1]);
        }
        return max(f[n-1],g[n-1]);
    } 
};
相关推荐
岁忧1 小时前
(LeetCode 面试经典 150 题 ) 11. 盛最多水的容器 (贪心+双指针)
java·c++·算法·leetcode·面试·go
chao_7891 小时前
二分查找篇——搜索旋转排序数组【LeetCode】两次二分查找
开发语言·数据结构·python·算法·leetcode
Maybyy3 小时前
力扣61.旋转链表
算法·leetcode·链表
chao_7896 小时前
二分查找篇——搜索旋转排序数组【LeetCode】一次二分查找
数据结构·python·算法·leetcode·二分查找
是白可可呀9 小时前
LeetCode 169. 多数元素
leetcode
YuTaoShao11 小时前
【LeetCode 热题 100】148. 排序链表——(解法二)分治
java·算法·leetcode·链表
蒟蒻小袁12 小时前
力扣面试150题--全排列
算法·leetcode·面试
緈福的街口14 小时前
【leetcode】2236. 判断根节点是否等于子节点之和
算法·leetcode·职场和发展
祁思妙想14 小时前
【LeetCode100】--- 1.两数之和【复习回滚】
数据结构·算法·leetcode
薰衣草233314 小时前
一天两道力扣(2)
算法·leetcode