【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]);
    } 
};
相关推荐
Navigator_Z12 小时前
LeetCode //C - 1293. Shortest Path in a Grid with Obstacles Elimination
c语言·算法·leetcode
Nil20813 小时前
leetcode 64最小路径和
算法·leetcode·职场和发展
Nil20813 小时前
leetcode 72编辑距离
算法·leetcode·职场和发展
Nil20814 小时前
leetcode 136只出现一次的数字
leetcode·哈希算法·散列表
局部有解19 小时前
LeetCode Hot100 438 找到字符串中所有字母异位词
c++·算法·leetcode
Nil20821 小时前
leetcode 75颜色分类
数据结构·算法·leetcode
aqiu11111121 小时前
CodeTop按顺序刷题0003:LeetCode 206. 反转链表(迭代法图文详解与动态演示)
算法·leetcode·链表
不会就选b1 天前
算法日常・每日刷题--<动态规划>29
数据结构·算法·leetcode
虚无的纽扣1 天前
【力扣刷题】第五天:将 x 减到 0 的最小操作数、最大连续1的个数 III
算法·leetcode·职场和发展
hanlin031 天前
刷题笔记:力扣第32题-最长有效括号
笔记·算法·leetcode