【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]);
    } 
};
相关推荐
且听风吟ayan2 小时前
leetcode day19 844+977
leetcode·c#
MiyamiKK572 小时前
leetcode_位运算 190.颠倒二进制位
python·算法·leetcode
C137的本贾尼2 小时前
解决 LeetCode 串联所有单词的子串问题
算法·leetcode·c#
Joyner20183 小时前
python-leetcode-找到字符串中所有字母异位词
算法·leetcode·职场和发展
ll7788113 小时前
LeetCode每日精进:225.用队列实现栈
c语言·开发语言·数据结构·算法·leetcode·职场和发展
不想编程小谭8 小时前
力扣LeetCode: 931 下降路径最小和
数据结构·c++·算法·leetcode·动态规划
Helene19008 小时前
Leetcode 224-基本计算器
算法·leetcode·职场和发展
Luo_LA9 小时前
【LeetCode Hot100 矩阵】矩阵置零、螺旋矩阵、旋转图像、搜索二维矩阵II
数据结构·算法·leetcode·矩阵
银河梦想家10 小时前
【Day44 LeetCode】图论问题 Ⅱ
算法·leetcode·图论
夏末秋也凉11 小时前
力扣-二叉树-617 合并二叉树
算法·leetcode