public class Solution { public IListSummaryRanges(int[] nums) { if(nums.Length == 0){ return new List (); } if(nums.Length == 1){ return new List (){nums[0].ToString()}; } var from = nums[0]; var to = nums[0]; var ret = new List (); for(var i = 1 ;i < nums.Length; i++){ if(nums[i] - nums[i-1] == 1){ to = nums[i]; if(i == nums.Length - 1){ ret.Add(string.Format({0}->{1}, from , to)); } } else{ if(from != to){ ret.Add(string.Format({0}->{1}, from , to)); if(i == nums.Length - 1 && to != nums[nums.Length - 1]){ ret.Add(nums[i].ToString()); } } else{ ret.Add(from.ToString()); if(i == nums.Length - 1){ ret.Add(nums[i].ToString()); } } from = nums[i]; to = nums[i]; } } return ret; } }