Tag: LeetCode: 56 Merge Intervals

  • LeetCode: 56 Merge Intervals

    LeetCode Problem: 56. Merge Intervals https://leetcode.com/problems/merge-intervals/description/ Problem Description: Given a collection of intervals, merge all overlapping intervals. Example: Input: intervals = [[1,3],[2,6],[8,10],[15,18]] Output: [[1,6],[8,10],[15,18]] Example 2: Input: intervals = [[1,4],[4,5]] Output: [[1,5]] Original Code (Using Sorting and Merging): class Solution: def merge(self, intervals: List[List[int]]) -> List[List[int]]: intervals.sort(key=lambda pair: pair[0]) #…