【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]);
    } 
};
相关推荐
爱编码的傅同学16 小时前
【今日算法】LeetCode 11.盛水最多的容器 15.三数之和 283.移动0
数据结构·算法·leetcode
alphaTao16 小时前
LeetCode 每日一题 2026/1/19-2026/1/25
算法·leetcode
Swift社区16 小时前
LeetCode 382 链表随机节点
算法·leetcode·链表
老鼠只爱大米17 小时前
LeetCode经典算法面试题 #19:删除链表的倒数第N个结点(双指针、栈辅助法等多种实现方案详细解析)
算法·leetcode·链表·双指针·删除链表节点·一趟扫描
漫随流水17 小时前
leetcode回溯算法(131.分割回文串)
数据结构·算法·leetcode·回溯算法
夏鹏今天学习了吗1 天前
【LeetCode热题100(92/100)】多数元素
算法·leetcode·职场和发展
源代码•宸1 天前
Leetcode—509. 斐波那契数【简单】
经验分享·算法·leetcode·面试·golang·记忆化搜索·动规
踩坑记录1 天前
leetcode hot100 206.反转链表 easy
leetcode
夏鹏今天学习了吗1 天前
【LeetCode热题100(90/100)】编辑距离
算法·leetcode·职场和发展
一分之二~1 天前
二叉树--层序遍历(迭代和递归)
数据结构·c++·算法·leetcode