Skip to content

Commit

Permalink
Time: 80 ms (29.92%) | Memory: 19.9 MB (39.60%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
ShatilKhan committed Mar 17, 2024
1 parent d372f6a commit 6a0e5ca
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 57-insert-interval/insert-interval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:
merged = []
i = 0

while i < len(intervals) and intervals[i][1] < newInterval[0]:
merged.append(intervals[i])
i += 1

while i < len(intervals) and intervals[i][0] <= newInterval[1]:
newInterval = [min(newInterval[0], intervals[i][0]), max(newInterval[1], intervals[i][1])]
i += 1
merged.append(newInterval)

while i < len(intervals):
merged.append(intervals[i])
i += 1

return merged

0 comments on commit 6a0e5ca

Please sign in to comment.