力扣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 天前
【华为OD】分割数组的最大差值
数据结构·算法·华为od
weixin_307779131 天前
最小曲面问题的欧拉-拉格朗日方程 / 曲面极值问题的变分法推导
算法
RTC老炮1 天前
webrtc弱网-AlrDetector类源码分析与算法原理
服务器·网络·算法·php·webrtc
孤廖1 天前
【算法磨剑:用 C++ 思考的艺术・Dijkstra 实战】弱化版 vs 标准版模板,洛谷 P3371/P4779 双题精讲
java·开发语言·c++·程序人生·算法·贪心算法·启发式算法
sali-tec1 天前
C# 基于halcon的视觉工作流-章33-矩状测量
开发语言·人工智能·算法·计算机视觉·c#
凯子坚持 c1 天前
Redis 核心数据结构:String 类型深度解析与 C++ 实战
数据结构·c++·redis
songx_991 天前
leetcode29( 有效的括号)
java·数据结构·算法·leetcode
于樱花森上飞舞1 天前
【java】常见排序算法详解
java·算法·排序算法
GawynKing1 天前
图论3 图的遍历
算法·深度优先
东方芷兰1 天前
Leetcode 刷题记录 21 —— 技巧
java·算法·leetcode·职场和发展·github·idea