当前位置:网站首页>1464. maximum product of two elements in an array
1464. maximum product of two elements in an array
2022-06-25 07:50:00 【AlbertOS】
introduce
Give you an array of integers nums, Please select two different subscripts of the array i and j, send (nums[i]-1)*(nums[j]-1) Get the maximum .
Please calculate and return the maximum value of the formula .
Example
Input :nums = [3,4,5,2]
Output :12
explain : If subscript is selected i=1 and j=2( Subscript from 0 Start ), The maximum value can be obtained ,(nums[1]-1)(nums[2]-1) = (4-1)(5-1) = 3*4 = 12 .
Input :nums = [1,5,4,5]
Output :16
explain : Select subscript i=1 and j=3( Subscript from 0 Start ), The maximum value can be obtained (5-1)*(5-1) = 16 .
Input :nums = [3,7]
Output :12
Answer key
2160. The smallest sum of the last four digits after splitting
Let's take a look at my question yesterday , We can find that the solution can be the same , One is to find the smallest two , One is to find the two largest ;
direct sort The sorting is over ~
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);
}
};
边栏推荐
猜你喜欢

OAuth 2.0一键登录那些事

Take you through the normalization flow of GaN
![[distillation] pointdistiller: structured knowledge distillationwards efficient and compact 3D detection](/img/5c/ad42474a363c33ecc0e01890b65bbf.png)
[distillation] pointdistiller: structured knowledge distillationwards efficient and compact 3D detection

El input to add words to the tail

环网冗余式CAN/光纤转换器的CAN光端机在消防火灾联网报警系统中的应用

Six causes of PCB disconnection 2021-10-20

基于STM32MP157调试MIPI-DSI屏幕

Application of point cloud intelligent drawing in intelligent construction site

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

Hisilicon 3559 sample parsing: Vio
随机推荐
@Resource和@Autowired注解的不同,为什么推荐@Resource?
C# 读取web上的xml
使用报文和波形记录分析仪RoyalScope的帧统计功能排查CAN总线偶发性故障
Modular programming of wireless transmission module nRF905 controlled by single chip microcomputer
Understand the reasons for impedance matching of PCB circuit board 2021-10-07
Audio (V) audio feature extraction
Accès à la boîte aux lettres du nom de domaine Lead à l'étranger
Basic use of ActiveMQ in Message Oriented Middleware
Pytorch遇到的坑:为什么模型训练时,L1loss损失无法下降?
realsense d455 semantic_ Slam implements semantic octree mapping
Five causes of PCB board deformation and six solutions 2021-10-08
Without "rice", you can cook "rice". Strategy for retrieving missing ground points under airborne lidar forest using "point cloud intelligent mapping"
What are the benefits of reserving process edges for PCB production? 2021-10-25
Do you know why the PCB produces tin beads? 2021-09-30
NSIS silent installation vs2013 runtime
@The difference between resource and @autowired annotation, why recommend @resource?
剑指 Offer II 027. 回文链表
国外LEAD域名邮箱获取途径
基于激光雷达的林业调查常用术语及含义锦集
How to use ad wiring for PCB design?