일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- 잡생각
- 만화도
- 사이드
- 스탭퍼
- 개발자
- leetcode
- 프로젝트
- 월간
- FIT XR
- 10분
- Writing
- 링피트
- 읽기
- 3줄정리
- 운동
- realclass
- 리얼 클래스
- 괜찮음
- 화상영어
- 파비최
- 매일
- Daily Challenge
- English
- 뭐든
- 영어원서읽기
- Problem Solving
- 쓰릴오브파이트
- 30분
- 미드시청
- 영어공부
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
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