mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
Update 0056.合并区间.md
Added python version code
This commit is contained in:
@ -168,7 +168,21 @@ class Solution {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
```python
|
||||||
|
class Solution:
|
||||||
|
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
|
||||||
|
if len(intervals) == 0: return intervals
|
||||||
|
intervals.sort(key=lambda x: x[0])
|
||||||
|
result = []
|
||||||
|
result.append(intervals[0])
|
||||||
|
for i in range(1, len(intervals)):
|
||||||
|
last = result[-1]
|
||||||
|
if last[1] >= intervals[i][0]:
|
||||||
|
result[-1] = [last[0], max(last[1], intervals[i][1])]
|
||||||
|
else:
|
||||||
|
result.append(intervals[i])
|
||||||
|
return result
|
||||||
|
```
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user