Skip to content

Commit

Permalink
Time: 6 ms (30.5%), Space: 41.6 MB (52.71%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-S-Sahu committed Oct 22, 2024
1 parent 620c146 commit 4982984
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions 0228-summary-ranges/0228-summary-ranges.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public List<String> summaryRanges(int[] nums) {
int n = nums.length;
List<String> ans = new ArrayList<>();
if (n == 0) return ans;

int start = 0;
for (int end = 1; end <= n; end++) {
if (end == n || nums[end] != nums[end - 1] + 1) {
if (start == end - 1) ans.add(String.valueOf(nums[start]));
else ans.add(nums[start] + "->" + nums[end - 1]);
start = end;
}
}
return ans;
}
}

0 comments on commit 4982984

Please sign in to comment.