精華區beta Marginalman 關於我們 聯絡資訊
https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/description 1464. Maximum Product of Two Elements in an Array 給你一個陣列找出任意兩個數-1相乘的最大值。 思路: 1.找最大的兩個數減一之後相乘 Java Code: ------------------------------------- class Solution { public int maxProduct(int[] nums) { int max1 = Integer.MIN_VALUE; int max2 = Integer.MIN_VALUE; for (int num : nums) { if (num > max1) { max2 = max1; max1 = num; } else if (num > max2) { max2 = num; } } return (max1 - 1) * (max2 - 1); } } ------------------------------------- LeetCode溫柔善良月 -- https://i.imgur.com/PIoxddO.jpg -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.250.69.212 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1702349557.A.21D.html
wwndbk: 大師 12/12 11:05
NCKUEECS: 開心easy 12/12 11:15