class Solution {
public List<String> summaryRanges(int[] nums) {
List<String> res = new ArrayList<>();
int n = nums.length;
for (int i = 0; i < n; i++) {
int start = nums[i];
while (i + 1 < n && nums[i + 1] - nums[i] == 1) {
i++;
}
if (start == nums[i]) {
res.add(String.valueOf(start));
} else {
res.add(start + "->" + nums[i]);
}
}
return res;
}
}
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)