class Solution {
fun maxProduct(nums: IntArray): Int {
// maxHeap
val pq = PriorityQueue<Int>(Collections.reverseOrder())
nums.forEach {
pq.offer(it)
}
return (pq.poll() - 1) * (pq.poll() - 1)
}
}
import kotlin.math.max
class Solution {
fun maxProduct(nums: IntArray): Int {
var biggest = 0 // 가장 큰 값
var bigger = 0 // 그 다음으로 큰 값
for (num in nums) {
if (num > biggest) {
bigger = biggest
biggest = num
} else if (num > bigger) bigger = num
}
return (biggest - 1) * (bigger - 1)
}
}