일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Generator
- Python Code
- Regular Expression
- LeetCode
- 715. Range Module
- 프로그래머스
- 밴픽
- 컴퓨터의 구조
- Python
- t1
- 시바견
- 315. Count of Smaller Numbers After Self
- data science
- Python Implementation
- 109. Convert Sorted List to Binary Search Tree
- concurrency
- Decorator
- Substring with Concatenation of All Words
- 파이썬
- DWG
- 43. Multiply Strings
- Convert Sorted List to Binary Search Tree
- kaggle
- iterator
- 운영체제
- Class
- Protocol
- attribute
- 30. Substring with Concatenation of All Words
- shiba
Archives
- Today
- Total
Scribbling
LeetCode: 57. Insert Interval 본문
class Solution:
def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:
ret = []
i = 0
for i, interval in enumerate(intervals):
if interval[0] <= newInterval[0]:
ret.append(interval)
else:
break
if ret and ret[-1][1] >= newInterval[0]:
ret[-1][1] = max(ret[-1][1], newInterval[1])
else:
ret.append(newInterval)
for j in range(i, len(intervals)):
interval = intervals[j]
if ret and ret[-1][1] >= interval[0]:
ret[-1][1] = max(ret[-1][1], interval[1])
else:
ret.append(interval)
return ret
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 59. Spiral Matrix II (0) | 2021.09.24 |
---|---|
LeetCode: 53. Maximum Subarray (0) | 2021.09.24 |
LeetCode: 56. Merge Intervals (0) | 2021.09.23 |
LeetCode: 54. Spiral Matrix (1) | 2021.09.17 |
LeetCode: 55. Jump Game (0) | 2021.09.15 |