Traverse the array directly. To determine whether it is continuous or not, it is only necessary to determine whether the current number and the following number are different by 1. When a discontinuity occurs, the current range is saved.
// need to consider the last number end = nums[nums.length - 1]; if (start != end) { results.add(start + "->" + end); } else { results.add(start + ""); }