Share C# clean 97.22% solution


  • 0
    L
    public class Solution {
        public IList<string> SummaryRanges(int[] nums) {
            int count=nums.Count();
            List<string> ans=new List<string>();
            if(count==0) return ans;
            string TEMP=Convert.ToString(nums[0]);
            int i,st=nums[0],sti=0;
            for(i=1;i<count;i++){
                if(nums[i]-st!=i-sti){
                    if(i-sti!=1)
                        TEMP=TEMP+"->"+Convert.ToString(nums[i-1]);
                    ans.Add(TEMP);
                    st=nums[i];
                    sti=i;
                    TEMP=Convert.ToString(nums[i]);
                }
            }
            if(nums[i-1]!=st && i>0)
                TEMP=TEMP+"->"+Convert.ToString(nums[i-1]);
            ans.Add(TEMP);
            return ans;
        }
    }

Log in to reply
 

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