Skip to content

Commit 6542e42

Browse files
committedJan 27, 2020
Add solution #628
1 parent 0cea3a1 commit 6542e42

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
565|[Array Nesting](./0565-array-nesting.js)|Medium|
2525
606|[Construct String from Binary Tree](./0606-construct-string-from-binary-tree.js)|Easy|
2626
617|[Merge Two Binary Trees](./0617-merge-two-binary-trees.js)|Easy|
27+
628|[Maximum Product of Three Numbers](./0628-maximum-product-of-three-numbers.js)|Easy|
2728
648|[Replace Words](./0648-replace-words.js)|Medium|
2829
686|[Repeated String Match](./0686-repeated-string-match.js)|Easy|
2930
722|[Remove Comments](./0722-remove-comments.js)|Medium|
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* 628. Maximum Product of Three Numbers
3+
* https://leetcode.com/problems/maximum-product-of-three-numbers/
4+
* Difficulty: Easy
5+
*
6+
* Given an integer array, find three numbers whose
7+
* product is maximum and output the maximum product.
8+
*/
9+
10+
/**
11+
* @param {number[]} nums
12+
* @return {number}
13+
*/
14+
var maximumProduct = function(nums) {
15+
const n = nums.length;
16+
nums.sort((a, b) => a - b);
17+
return Math.max(nums[0] * nums[1] * nums[n - 1], nums[n - 1] * nums[n - 2] * nums[n - 3]);
18+
};

0 commit comments

Comments
 (0)
Please sign in to comment.