Skip to content

Commit d25e0d5

Browse files
authored
Create Solution.java
1 parent 5c1544a commit d25e0d5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public List<String> summaryRanges(int[] nums) {
3+
List<String> res = new ArrayList<>();
4+
for (int i = 0, j = 1; i < nums.length; i = j, ++j) {
5+
while (j < nums.length && nums[j] - nums[j - 1] == 1) {
6+
++j;
7+
}
8+
if (j - i == 1) {
9+
res.add(String.valueOf(nums[i]));
10+
} else {
11+
res.add(nums[i] + "->" + nums[j - 1]);
12+
}
13+
}
14+
return res;
15+
}
16+
}

0 commit comments

Comments
 (0)