일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 괜찮음
- Daily Challenge
- 월간
- 파비최
- 화상영어
- FIT XR
- 영어공부
- realclass
- 사이드
- English
- 프로젝트
- 30분
- 미드시청
- 만화도
- 뭐든
- 링피트
- 읽기
- 영어원서읽기
- 스탭퍼
- 3줄정리
- 개발자
- leetcode
- 잡생각
- Writing
- 운동
- 리얼 클래스
- 매일
- Problem Solving
- 10분
- 쓰릴오브파이트
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.01.16 Today's Challenge 본문
https://leetcode.com/problems/insert-interval/
Insert Interval - LeetCode
Insert Interval - You are given an array of non-overlapping intervals intervals where intervals[i] = [starti, endi] represent the start and the end of the ith interval and intervals is sorted in ascending order by starti. You are also given an interval new
leetcode.com
머지 인터벌을 활용해서 문제 풂
class Solution:
def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:
insert_i = bisect_left(intervals, newInterval)
intervals.insert(insert_i, newInterval)
stack = []
for s,e in intervals:
if stack and stack[-1][1] >= s:
last_s, last_e = stack.pop()
stack.append([last_s, max(last_e,e)])
else:
stack.append([s,e])
return stack
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.01.18 Today's Challenge (0) | 2023.01.18 |
---|---|
2023.01.17 Today's Challenge (0) | 2023.01.17 |
Today's Challenge (0) | 2023.01.15 |
Today's Challenge (0) | 2023.01.14 |
Today's Challenge (0) | 2023.01.13 |
Comments