Post

leetcode(리트코드)-1464 Maximum Product of Two Elements in an Array(PYTHON)

leetcode 1464 - Maximum Product of Two Elements in an Array 문제입니다.

1. 문제

https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/


2. Input , Output


3. 분류 및 난이도

Eazy 난이도 문제입니다.


4. 문제 해석

  • array가 들어옵니다.
  • 가장 큰값과 두 번째로 큰 값을 찾아 각 값 - 1을 곱한 결과를 리턴하세요.

5. code

코드설명

  • 정렬해서 요소 두개 곱하기

python

1
2
3
4
class Solution:
    def maxProduct(self, nums: List[int]) -> int:
        nums.sort()
        return (nums[-1]-1) * (nums[-2] - 1)

6. 결과 및 후기, 개선점

필요시 c++로 짜드립니다.

설명이 필요하다면 댓글을 달아주세요.

This post is licensed under CC BY 4.0 by the author.