File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 24
24
565|[ Array Nesting] ( ./0565-array-nesting.js ) |Medium|
25
25
606|[ Construct String from Binary Tree] ( ./0606-construct-string-from-binary-tree.js ) |Easy|
26
26
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|
27
28
648|[ Replace Words] ( ./0648-replace-words.js ) |Medium|
28
29
686|[ Repeated String Match] ( ./0686-repeated-string-match.js ) |Easy|
29
30
722|[ Remove Comments] ( ./0722-remove-comments.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments