138. Copy List with Random Pointer

681 ワード

class Solution:
    def merge(self, intervals: List[List[int]]) -> List[List[int]]:
        
        intervals.sort(key=lambda x: x[0])
        
        merged = []
        
        for i in intervals:
            if not merged or merged[-1][1] < i[0]:
                merged.append(i)
            else:
                merged[-1][1] = max(merged[-1][1], i[1])
        
        return merged
        
Runtime: 80 ms, faster than 89.80% of Python3 online submissions for Merge Intervals.
Memory Usage: 16.2 MB, less than 9.17% of Python3 online submissions for Merge Intervals.
Pythonは気が狂ったのか...?
この速度は5%から89.80%まで多様化している.