Answer by Zuabros for Leetcode 56: Merge Intervals
Using a list allows just excluding redundant intervals. I think it is cleaner. The trick is backwarding the counter when you remove an element. Some people say against using "Math.Max", but the...
View ArticleAnswer by tinstaafl for Leetcode 56: Merge Intervals
I would suggest that a custom comparer would work better than orderby, since 2 intervals with the same start won't necessarily get sorted right:public IList<Interval> Merge(IList<Interval>...
View ArticleAnswer by bushed for Leetcode 56: Merge Intervals
Given something like that at work and depending on the usage/location I'd suggest making Interval generic:public class Interval<T> where T : IComparable<T>{ public T Start { get; set; }...
View ArticleAnswer by paparazzo for Leetcode 56: Merge Intervals
Don't use lower case for public and don't us single letters in ctor public class Interval { public int start; public int end; public Interval() { start = 0; end = 0; } public Interval(int s, int e) {...
View ArticleLeetcode 56: Merge Intervals
Problem statementGiven 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]\$.My introduction of algorithm:I worked...
View Article