https://leetcode-cn.com/problems/summary-ranges/
这道题很简单,但是对于数组的下标之类的不能很快理清楚,有时候越写越乱,注意!
List<String> list = new ArrayList<String>();
int i=0;
int n = nums.length;
while(i<n) {
int low = i;
i++;
while(i<n && nums[i] == nums[i-1]+1) {
i++;
}
int high = i-1;
StringBuilder temp = new StringBuilder();
temp.append(nums[low]);
if(low < high) {
temp.append("->");
temp.append(nums[high]);
}
list.add(temp.toString());
}
return list;