当前位置:网站首页>Maximum product of three numbers in question 628 of Li Kou
Maximum product of three numbers in question 628 of Li Kou
2022-07-06 22:04:00 【Big chicken legs are best】
628. The maximum product of three numbers
The difficulty is simple 353 Switch to English to receive dynamic feedback
Here's an integer array nums
, Find the largest product of three numbers in the array , And output this product .
Example 1:
Input :nums = [1,2,3] Output :6
Example 2:
Input :nums = [1,2,3,4] Output :24
Example 3:
Input :nums = [-1,-2,-3] Output :-6
/**
* @param {number[]} nums
* @return {number}
*/
var maximumProduct = function(nums) {
nums=nums.sort((a,b)=> {return a-b})
let len=nums.length-1
let l=nums[0]*nums[1]*nums[len]
let p=nums[len-2]*nums[len-1]*nums[len]
let c=Math.max(l,p)
return c
};
边栏推荐
- [Yu Yue education] higher mathematics of Nanchang University (2) reference materials
- Shake Sound poussera l'application indépendante de plantation d'herbe "louable", les octets ne peuvent pas oublier le petit livre rouge?
- Oracle性能分析3:TKPROF简介
- Method return value considerations
- MPLS experiment
- 华为在多个行业同时出击,吓人的技术让欧美企业瑟瑟发抖
- Some problems about the use of char[] array assignment through scanf..
- 功能强大的国产Api管理工具
- 50 commonly used numpy function explanations, parameters and usage examples
- Yyds dry goods inventory C language recursive implementation of Hanoi Tower
猜你喜欢
爬虫实战(五):爬豆瓣top250
Sequoia China, just raised $9billion
Uni app app half screen continuous code scanning
【MySQL】Online DDL详解
一行代码可以做些什么?
Why rdd/dataset is needed in spark
[Chongqing Guangdong education] Information Literacy of Sichuan Normal University: a new engine for efficiency improvement and lifelong learning reference materials
[asp.net core] set the format of Web API response data -- formatfilter feature
GPS从入门到放弃(十四)、电离层延时
Bat script learning (I)
随机推荐
Mongodb (III) - CRUD
[Yu Yue education] reference materials for surgical skills teaching in Tongji University
UNI-Admin基础框架怎么关闭创建超级管理员入口?
Yyds dry goods inventory C language recursive implementation of Hanoi Tower
Huawei has launched attacks in many industries at the same time, and its frightening technology has made European and American enterprises tremble
GPS from getting started to giving up (XIII), receiver autonomous integrity monitoring (RAIM)
Happy sound 2[sing.2]
[Chongqing Guangdong education] Tianjin urban construction university concrete structure design principle a reference
QT | UDP broadcast communication, simple use case
GPS从入门到放弃(十六)、卫星时钟误差和卫星星历误差
Broadcast variables and accumulators in spark
GPS from getting started to giving up (XV), DCB differential code deviation
Search map website [quadratic] [for search map, search fan, search book]
Record the process of cleaning up mining viruses
Method return value considerations
GNN, please deepen your network layer~
Qt | UDP广播通信、简单使用案例
JPEG2000-Matlab源码实现
华为在多个行业同时出击,吓人的技术让欧美企业瑟瑟发抖
Why rdd/dataset is needed in spark