We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7dba398 commit adfabe0Copy full SHA for adfabe0
problems/summary_ranges/solution.rs
@@ -0,0 +1,31 @@
1
+impl Solution {
2
+ pub fn summary_ranges(nums: Vec<i32>) -> Vec<String> {
3
+ let mut ans = Vec::new();
4
+ if nums.is_empty() {
5
+ return Vec::new();
6
+ }
7
+ let mut current_range = (nums[0], nums[0]);
8
+
9
+ for num in &nums[1..] {
10
+ if *num == current_range.1 + 1 {
11
+ current_range.1 += 1;
12
+ } else {
13
+ if current_range.0 == current_range.1 {
14
+ ans.push(format!("{}", current_range.0))
15
16
+ ans.push(format!("{}->{}", current_range.0, current_range.1));
17
18
+ current_range = (*num, *num);
19
20
21
22
23
24
25
26
+ };
27
28
+ ans
29
30
31
+}
0 commit comments