// 1464. Maximum Product of Two Elements in an Array
class Solution {
public int maxProduct(int[] nums) {
int first = 0;
int second = 0;
for (int num : nums) {
if (num > first) {
second = first;
first = num;
} else if (num > second) {
second = num;
}
}
return (first - 1) * (second - 1);
}
}
学习笔记: 今天又是一道数组的入门题,就只需要维护两个变量即可。