Quantcast
Channel: Leetcode 56: Merge Intervals - Code Review Stack Exchange
Browsing all 5 articles
Browse latest View live

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 Article



Answer 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 Article

Answer 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 Article

Answer 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 Article

Leetcode 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

Browsing all 5 articles
Browse latest View live




Latest Images