2874. Maximum Value of an Ordered Triplet II - Medium
前往題目
想法
- 與昨天的daily題目一模一樣,只是這次不允許$n^3$複雜度暴力解法
思路
Code
class Solution {
public long maximumTripletValue(int[] nums) {
long maxVal = 0, maxTriplet = 0, maxDiff = 0;
for (int num : nums) {
maxTriplet = Math.max(maxTriplet, maxDiff * num);
maxVal = Math.max(maxVal, num);
maxDiff = Math.max(maxDiff, maxVal - num);
}
return maxTriplet;
}
}
2874. Maximum Value of an Ordered Triplet II - Medium
https://f88083.github.io/2025/04/03/2874-Maximum-Value-of-an-Ordered-Triplet-II-Medium/