Re: [閒聊] 每日LeetCode已回收

看板Marginalman作者 (みけねこ的鼻屎)時間2年前 (2023/12/12 10:52), 編輯推噓1(101)
留言2則, 2人參與, 2年前最新討論串574/719 (看更多)
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

12/12 11:05, 2年前 , 1F
大師
12/12 11:05, 1F

12/12 11:15, 2年前 , 2F
開心easy
12/12 11:15, 2F
文章代碼(AID): #1bTyhr8T (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1bTyhr8T (Marginalman)