当前位置:网站首页>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);
}
};
边栏推荐
- OpenMP入门
- AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
- (tool class) use SecureCRT as the communication medium
- opencv最小值滤波(不局限于图像)
- WinForm implementation window is always at the top level
- Redis learning notes
- Unity3D邪门实现之GUI下拉菜单Dropdown设计无重复项
- [batch dos-cmd command - summary and summary] - CMD window setting and operation commands (CD, title, mode, color, pause, CHCP, exit)
- JMeter introduction practice ----- use of global variables and local variables
- This year, I graduated
猜你喜欢
smartBugs安装小问题总结
VectorDraw Developer Framework 10.10
realsense d455 semantic_ Slam implements semantic octree mapping
差点被这波Handler 面试连环炮带走~
【蒸馏】PointDistiller: Structured Knowledge DistillationTowards Efficient and Compact 3D Detection
Application scheme | application of Sichuan earth microelectronics ca-is398x in PLC field
Sichuan Tuwei ca-if1051 can transceiver has passed aec-q100 grade 1 certification
Research on 3D model retrieval method based on two channel attention residual network - Zhou Jie - paper notes
Three years of continuous decline in revenue, Tiandi No. 1 is trapped in vinegar drinks
Tupu software digital twin 3D wind farm, offshore wind power of smart wind power
随机推荐
[batch dos-cmd command - summary and summary] - CMD extended command and function (CMD /e:on, CMD /e:off)
VectorDraw Developer Framework 10.10
Shell tips (134) simple keyboard input recorder
Lebel only wants an asterisk in front of it, but doesn't want to verify it
OpenMP入门
VectorDraw Developer Framework 10.10
Modular programming of oled12864 display controlled by single chip microcomputer
LeetCode_哈希表_中等_454.四数相加 II
国外LEAD域名邮箱获取途径
指南针可以开股票账户吗?安全吗?
不同路径II[针对DFS的动态规划改进]
[batch dos-cmd command - summary and summary] - add comment command (REM or::)
Distributed quorum NWR of the alchemy furnace of the Supreme Master
函数模板_类模板
[batch dos-cmd command - summary and summary] - commands related to Internet access and network communication (Ping, Telnet, NSLOOKUP, ARP, tracert, ipconfig)
Path planner based on time potential function in dynamic environment
This year, I graduated
OAuth 2.0 one click login
Misunderstanding of switching triode
单位转换-毫米转像素-像素转毫米