Runtime error but running fine in VS2012 editor


  • 0
    A

    The following code is running okay for the input set [1,4], [1,4] in visual studio 2012 editor and gives the expected result [1,4]. But while submitting the code in Leetcode its throwing run time error. Any help is appreciated.

    public class Solution
    {
    public IList<Interval> Execute(IList<Interval> intervals)
    {

            for (int i = 0; i < intervals.Count; i++)
            {
                if (i == 0)
                {
                    continue;
                }
    
                if (intervals[i - 1].end > intervals[i].start)
                {
                    intervals[i - 1].end = intervals[i].end;
    
                    Interval objInterval = new Interval();
                    objInterval = intervals[i];
    
                    intervals.Remove(objInterval);
                }
    
            }
    
            return intervals;
        }
    
    }
    
    public class Interval
    {
        public int start;
        public int end;
        public Interval() { start = 0; end = 0; }
        public Interval(int s, int e) { start = s; end = e; }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.