当前位置:网站首页>1464. 数组中两元素的最大乘积
1464. 数组中两元素的最大乘积
2022-06-25 06:41:00 【AlbertOS】
引入
给你一个整数数组 nums,请你选择数组的两个不同下标 i 和 j,使 (nums[i]-1)*(nums[j]-1) 取得最大值。
请你计算并返回该式的最大值。
示例
输入:nums = [3,4,5,2]
输出:12
解释:如果选择下标 i=1 和 j=2(下标从 0 开始),则可以获得最大值,(nums[1]-1)(nums[2]-1) = (4-1)(5-1) = 3*4 = 12 。
输入:nums = [1,5,4,5]
输出:16
解释:选择下标 i=1 和 j=3(下标从 0 开始),则可以获得最大值 (5-1)*(5-1) = 16 。
输入:nums = [3,7]
输出:12
题解
2160. 拆分数位后四位数字的最小和
这题大家再看看我昨天的那题,就可以发现解法可以一样,一个是找出最小的两个,一个是找出最大的两个;
直接sort排序就完了~
class Solution {
public:
int maxProduct(vector<int>& nums) {
int len = nums.size();
sort(nums.begin(),nums.end());
return (nums[len-1]-1)*(nums[len-2]-1);
}
};
边栏推荐
- PI Ziheng embedded: This paper introduces the multi-channel link mode of i.mxrt timer pit and its application in coremark Test Engineering
- China Mobile MCU product information
- opencv最小值滤波(不局限于图像)
- 基于激光雷达的林业调查常用术语及含义锦集
- [pytest] modify the logo and parameterization in the allure Report
- [Batch dos - cmd Command - Summary and Summary] - cmd extension Command, extension Function (CMD / E: on, CMD / E: off)
- Pytorch遇到的坑:为什么模型训练时,L1loss损失无法下降?
- Evolution of Alibaba e-commerce architecture
- [batch dos-cmd command - summary and summary] - CMD window setting and operation commands (CD, title, mode, color, pause, CHCP, exit)
- Five causes of PCB board deformation and six solutions 2021-10-08
猜你喜欢
![Insert and sort the linked list [dummy unified operation + broken chain core - passive node]](/img/2a/ccb1145d2b4f9fbd8d0812deace93b.png)
Insert and sort the linked list [dummy unified operation + broken chain core - passive node]

Hisilicon 3559 sample parsing: Vio
![[batch dos-cmd command - summary and summary] - application startup and call, service and process operation commands (start, call, and)](/img/19/b8c0fb72f1c851a6b97f2c17a18665.png)
[batch dos-cmd command - summary and summary] - application startup and call, service and process operation commands (start, call, and)

ELK + filebeat日志解析、日志入库优化 、logstash过滤器配置属性

【批处理DOS-CMD命令-汇总和小结】-文件与目录操作命令(md、rd、xcopy、dir、cd、set、move、copy、del、type、sort)

OAuth 2.0 one click login

Without "rice", you can cook "rice". Strategy for retrieving missing ground points under airborne lidar forest using "point cloud intelligent mapping"

GUI pull-down menu of unity3d evil door implementation dropdown design has no duplicate items

数据可视化没有重点怎么办?

Distributed quorum NWR of the alchemy furnace of the Supreme Master
随机推荐
Bicubic difference
OpenMP入门
Function template_ Class template
Pytorch遇到的坑:为什么模型训练时,L1loss损失无法下降?
Insert and sort the linked list [dummy unified operation + broken chain core - passive node]
2265. 统计值等于子树平均值的节点数
Chuantu microelectronics 𞓜 subminiature package isolated half duplex 485 transceiver
Static bit rate (CBR) and dynamic bit rate (VBR)
“空间转换”显著提升陡崖点云的地面点提取质量
不同路径II[针对DFS的动态规划改进]
SSL证书免费获取教程
差点被这波Handler 面试连环炮带走~
C Getting Started tutorial
三年营收连续下滑,天地壹号困在醋饮料里
國外LEAD域名郵箱獲取途徑
Home environment monitoring system design (PC version) (mobile app version to be determined)
Modular programming of oled12864 display controlled by single chip microcomputer
shell小技巧(一百三十四)简单的键盘输入记录器
WinForm implementation window is always at the top level
RTKLIB-b33版本中GALILEO广播星历存储问题