LeetCode 1464数组中两元素的最大乘积(java)

it2024-06-19  42

class Solution { public int maxProduct(int[] nums) { int temp1 = nums[0], temp2 = nums[1]; for(int i = 2; i< nums.length; i ++) { if(temp1 > temp2) temp2 = nums[i] > temp2 ? nums[i] : temp2; else temp1 = nums[i] > temp1 ? nums[i] : temp1; } return (temp1 -1) * (temp2 - 1); } }
最新回复(0)