Simple JavaScript solution


  • 0
    L
    function summaryRanges(nums) {
      var res = [];
      for (var i = 0, left = nums[0]; i < nums.length; i++) {
        if (nums[i] + 1 !== nums[i + 1]) {
          res.push(left === nums[i] ? '' + nums[i] : left + '->' + nums[i]);
          left = nums[i + 1];
        }
      }
      return res;
    }

Log in to reply
 

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