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