Tuesday, February 16, 2016

LeetCode Q56: Merge Intervals

Given a collection of intervals, merge all overlapping intervals.
For example,
Given [1,3],[2,6],[8,10],[15,18],
return [1,6],[8,10],[15,18].

Nothing hard, but need to be careful when using vector::erase.
For example, when erase elements from i to j in A. 
When j>i, to remove [A[i], A[j]]:
erase(a.begin()+i, a.begin()+j+1)
because, erase(A.begin()+i, A.begin()+j), actually only remove [i, j) from A.
When j==i, to remove A[i]:
erase(A.begin()+i)




Round 2 solution:

No comments:

Post a Comment