Movatterモバイル変換


[0]ホーム

URL:


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

Commit3985d27

Browse files
authored
Create 1464_Maximum_Product_of_Two_Elements_in_an_Array.java
1 parent10b8107 commit3985d27

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// id: 1464
2+
// Name: Maximum Product of Two Elements in an Array
3+
// link: https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/
4+
// Difficulty: Easy
5+
6+
classSolution {
7+
publicintmaxProduct(int[]nums) {
8+
intmax =0;
9+
intsecondMax =0;
10+
for (intn:nums) {
11+
if (n >max) {
12+
secondMax =max;
13+
max =n;
14+
}elseif (n >secondMax) {
15+
secondMax =n;
16+
}
17+
}
18+
return (max-1) * (secondMax-1);
19+
}
20+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp