Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 15cf252

Browse files
Merge pull request #28 from knaxus/max-product-of-3-numbers
max-product-of-3-numbers error throw
2 parents fb7e5a9 + 01f33e1 commit 15cf252

File tree

1 file changed

+2
-2
lines changed
  • src/_Problems_/max-product-of-3-numbers

1 file changed

+2
-2
lines changed

‎src/_Problems_/max-product-of-3-numbers/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
/** The following solution is O(nlogn) because of sorting */
1111
function maxProductof3Numbers(arr) {
12-
if (!Array.isArray(arr)) {
12+
if (!Array.isArray(arr)||arr.length<3) {
1313
throw new Error('Invalid Argument');
1414
}
1515

@@ -30,7 +30,7 @@ function maxProductof3Numbers(arr) {
3030

3131
/** The following solution is O(n) */
3232
function maxProductof3NumbersII(arr) {
33-
if (!Array.isArray(arr)) {
33+
if (!Array.isArray(arr)||arr.length<3) {
3434
throw new Error('Invalid Argument');
3535
}
3636

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /