added solution for mergeIntervals