力扣2874.有序三元组中的最大值 II

力扣2874.有序三元组中的最大值 II

  • 遍历j --> 找j左边最大数 和右边最大数

cpp 复制代码
  class Solution {
  public:
      long long maximumTripletValue(vector<int>& nums) {
          int n = nums.size();
          vector<int> suf_max(n+1,0);
          //右边最大数
          for(int i=n-1;i>1;i--)
          {
              suf_max[i] = max(suf_max[i+1] , nums[i]);
          }
          long long res=0;
          //左边最大数
          int pre_max = nums[0];
          for(int j=1;j<n-1;j++)
          {
              res = max(res, (long long)(pre_max - nums[j]) * suf_max[j + 1]);
              pre_max = max(pre_max,nums[j]);
          }
          return res;
      }
  };
相关推荐
今晚打老虎1 小时前
c++之提高A(前缀和)(第三课)
数据结构·c++·算法
不会就选b2 小时前
算法日常・每日刷题--<贪心>26
数据结构·算法
hetao17338374 小时前
2026-09-29 hetao1733837 的刷题记录
c++·算法
欣欣之王来了4 小时前
AI合规专项:AI算法透明度的合规要求
人工智能·算法
wzdark4 小时前
分块思想在算法优化中的实践与应用4
算法
Because_of_Her14 小时前
dfs-洪水填充技巧
笔记·算法·深度优先·洪水填充
小静AI工程实验室5 小时前
RSA 算法详解:从模幂原理到 OAEP 加密、PSS 签名与 Python 实验
python·算法
xzal125 小时前
GESP Python笔记
笔记·python·算法
wzdark5 小时前
算法中的记忆化思想与重复子问题优化4
算法
Discipline10295 小时前
流水线运行是否正随时间变得更加集中?
算法