파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 7. 2. 23:45

https://leetcode.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/

 

Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

set을 써서 구현.
문제에 주어진 조건대로 풀면 됨. 10^9 + 7 mod 연산 때문에 좀 쫄긴했는데
사실 그냥 간격 나눠진 값들 중 h, w의 가장 큰 값만 가져와서 계산하면 되는 간단한 문제.

class Solution:
    def maxArea(self, h: int, w: int, hc: List[int], vc: List[int]) -> int:
        dh, dv = set(), set()
        hc = sorted([0] + hc + [h])
        vc = sorted([0] + vc + [w])
        for i in range(1, len(hc)):
            dh.add(hc[i] - hc[i-1])
        for i in range(1, len(vc)):
            dv.add(vc[i] - vc[i-1])
        return (sorted(dh)[-1]*sorted(dv)[-1]) % 1000000007
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.07.04
Today's Challenge  (0) 2022.07.03
Today's Challenge  (0) 2022.07.01
Today's Challenge  (0) 2022.06.30
Today's Challenge  (0) 2022.06.29
Comments