funcmerge(intervals[][]int)[][]int{n:=len(intervals)sort.Slice(intervals,func(i,jint)bool{a,b:=intervals[i],intervals[j]returna[0]<b[0]||a[0]==b[0]&&a[1]>b[1]})varans[][]intleft,right:=intervals[0][0],intervals[0][1]fori:=1;i<n;i++{ifintervals[i][0]==intervals[i-1][0]{continue}elseifintervals[i][0]<=right{ifintervals[i][1]>right{right=intervals[i][1]}}else{// intervals[i][0] > right
ans=append(ans,[]int{left,right})left,right=intervals[i][0],intervals[i][1]}}ans=append(ans,[]int{left,right})returnans}