当前位置:网站首页>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);
}
};
边栏推荐
- 搞清信息化是什么,让企业转型升级走上正确的道路
- 三台西门子消防主机FC18配套CAN光端机进行光纤冗余环网组网测试
- Summary of small problems in smartbugs installation
- Atlassian Confluence 远程代码执行漏洞(CVE-2022-26134漏洞分析与防护
- 差点被这波Handler 面试连环炮带走~
- C get the version number of exe - file version and assembly version
- 国外LEAD域名邮箱获取途径
- Take you through the normalization flow of GaN
- One "stone" and two "birds", PCA can effectively improve the dilemma of missing some ground points under the airborne lidar forest
- Tips 𞓜 how to clean PCB boards 2021-10-22
猜你喜欢

STL tutorial 4- input / output stream and object serialization

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

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

Share the process requirements for single-layer flexible circuit board

Knowledge sharing 𞓜 conventional laminated structure of six layer PCB

消息中间件之ActiveMQ的基本使用
![Different paths ii[dynamic planning improvement for DFS]](/img/bb/1e1cee22b9de954de242d299a1a0eb.png)
Different paths ii[dynamic planning improvement for DFS]

How to use printf of 51 single chip microcomputer

基于RBAC 的SAAS系统权限设计

"Spatial transformation" significantly improves the quality of ground point extraction of cliff point cloud
随机推荐
RTKLIB-b33版本中GALILEO广播星历存储问题
Five causes of PCB board deformation and six solutions 2021-10-08
“空间转换”显著提升陡崖点云的地面点提取质量
Summary of small problems in smartbugs installation
Mysql面试-执行sql响应比较慢,排查思路。
How to use printf of 51 single chip microcomputer
Share the process requirements for single-layer flexible circuit board
useMemo模拟useCallback
Home environment monitoring system design (PC version) (mobile app version to be determined)
50. Pow(x, n)-快速幂
判断用户是否是第一次进入某个页面
Understand the reasons for impedance matching of PCB circuit board 2021-10-07
消息中间件之ActiveMQ的基本使用
【深度学习 轻量型backbone】2022 EdgeViTs CVPR
Storage of Galileo broadcast ephemeris in rtklib-b33
Terms and concepts related to authority and authentication system
用函数的递归来解决几道有趣的题
VSCode很好,但我以后不会再用了
Audio (V) audio feature extraction
一次弄清楚 Handler 可能导致的内存泄漏和解决办法