力扣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;
      }
  };
相关推荐
三毛的二哥18 小时前
BEV:典型BEV算法总结
人工智能·算法·计算机视觉·3d
南宫萧幕19 小时前
自控PID+MATLAB仿真+混动P0/P1/P2/P3/P4构型
算法·机器学习·matlab·simulink·控制·pid
故事和你9120 小时前
洛谷-数据结构1-4-图的基本应用1
开发语言·数据结构·算法·深度优先·动态规划·图论
我叫黑大帅21 小时前
为什么map查找时间复杂度是O(1)?
后端·算法·面试
炽烈小老头21 小时前
【每天学习一点算法 2026/04/20】除自身以外数组的乘积
学习·算法
skilllite作者21 小时前
AI agent 的 Assistant Auto LLM Routing 规划的思考
网络·人工智能·算法·rust·openclaw·agentskills
破浪前行·吴1 天前
数据结构概述
数据结构·学习
py有趣1 天前
力扣热门100题之不同路径
算法·leetcode
_日拱一卒1 天前
LeetCode:25K个一组翻转链表
算法·leetcode·链表
啊哦呃咦唔鱼1 天前
LeetCodehot100-394 字符串解码
算法