Skip to content

Commit

Permalink
Create 1464_Maximum_Product_of_Two_Elements_in_an_Array.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhuzaima committed Dec 12, 2023
1 parent 10b8107 commit 3985d27
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 1464_Maximum_Product_of_Two_Elements_in_an_Array.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// id: 1464
// Name: Maximum Product of Two Elements in an Array
// link: https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/
// Difficulty: Easy

class Solution {
public int maxProduct(int[] nums) {
int max = 0;
int secondMax = 0;
for (int n: nums) {
if (n > max) {
secondMax = max;
max = n;
} else if (n > secondMax) {
secondMax = n;
}
}
return (max-1) * (secondMax-1);
}
}

0 comments on commit 3985d27

Please sign in to comment.