Skip to content

Latest commit

 

History

History
50 lines (32 loc) · 1.03 KB

_56. Merge Intervals.md

File metadata and controls

50 lines (32 loc) · 1.03 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 18, 2024

Last updated : June 18, 2024


Related Topics : Array, Sorting

Acceptance Rate : 47.508 %


Solutions

Python

class Solution:
    def merge(self, intervals: List[List[int]]) -> List[List[int]]:
        stk = []

        intervals.sort(key=lambda x: x[0], reverse=True)
        
        while intervals :
            start, stop = intervals.pop()

            if not stk :
                stk.append([start, stop])
                continue

            if stk[-1][1] < start :
                stk.append([start, stop])
            elif stk[-1][1] < stop :
                stk[-1][1] = stop
            

        return stk