当前位置:网站首页>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);
}
};
边栏推荐
- [batch dos-cmd command - summary and summary] - add comment command (REM or::)
- Runtime——methods成员变量,cache成员变量
- Tuwei Digital Isolator and interface chip can perfectly replace imported brands Ti and ADI
- Ns32f103c8t6 can perfectly replace stm32f103c8t6
- Leetcode daily question - 515 Find the maximum value in each tree row
- GUI pull-down menu of unity3d evil door implementation dropdown design has no duplicate items
- JDBC-DAO层实现
- 57. 插入区间
- Estimation of dense forest volume based on LIDAR point cloud with few ground points
- Bicubic difference
猜你喜欢

opencv最小值滤波(不局限于图像)

Unity3D邪门实现之GUI下拉菜单Dropdown设计无重复项

What if there is no point in data visualization?

一次弄清楚 Handler 可能导致的内存泄漏和解决办法
![[batch dos-cmd command - summary and summary] - file and directory operation commands (MD, RD, xcopy, dir, CD, set, move, copy, del, type, sort)](/img/fd/1d83ab3b318413ddf70f4e68b28cc3.png)
[batch dos-cmd command - summary and summary] - file and directory operation commands (MD, RD, xcopy, dir, CD, set, move, copy, del, type, sort)

Modular programming of wireless transmission module nRF905 controlled by single chip microcomputer

npm install 报错 : gyp ERR! configure error

Sichuan Tuwei ca-is3105w fully integrated DC-DC converter

神经网络与深度学习-3- 机器学习简单示例-PyTorch

VectorDraw Web Library 10.10
随机推荐
Lebel only wants an asterisk in front of it, but doesn't want to verify it
Chuantu microelectronics high speed and high performance rs-485/422 transceiver series
STL tutorial 4- input / output stream and object serialization
Tuwei Digital Isolator and interface chip can perfectly replace imported brands Ti and ADI
NPM install reports an error: gyp err! configure error
Explain distributed raft with dynamic diagram
Full range of isolator chips with integrated isolated power supply
What is the difference between norflash and nandflash
OpenMP入门
VectorDraw Developer Framework 10.10
smartBugs安装小问题总结
ELK + filebeat日志解析、日志入库优化 、logstash过滤器配置属性
Four software 2021-10-14 suitable for beginners to draw PCB
IAR compiler flashback
Sichuan earth microelectronics ca-is1300 isolated operational amplifier for current detection is on the market
Research on 3D model retrieval method based on two channel attention residual network - Zhou Jie - paper notes
VectorDraw Developer Framework 10.10
函数模板_类模板
C get the version number of exe - file version and assembly version
对链表进行插入排序[dummy统一操作+断链核心--被动节点]