228. Summary Ranges Easy

@problem@discussion
#Array



1/**
2 * [228] Summary Ranges
3 *
4 * You are given a sorted unique integer array nums.
5 * A range [a,b] is the set of all integers from a to b (inclusive).
6 * Return the smallest sorted list of ranges that cover all the numbers in the array exactly. That is, each element of nums is covered by exactly one of the ranges, and there is no integer x such that x is in one of the ranges but not in nums.
7 * Each range [a,b] in the list should be output as:
8 * 
9 * 	"a->b" if a != b
10 * 	"a" if a == b
11 * 
12 *  
13 * Example 1:
14 * 
15 * Input: nums = [0,1,2,4,5,7]
16 * Output: ["0->2","4->5","7"]
17 * Explanation: The ranges are:
18 * [0,2] --> "0->2"
19 * [4,5] --> "4->5"
20 * [7,7] --> "7"
21 * 
22 * Example 2:
23 * 
24 * Input: nums = [0,2,3,4,6,8,9]
25 * Output: ["0","2->4","6","8->9"]
26 * Explanation: The ranges are:
27 * [0,0] --> "0"
28 * [2,4] --> "2->4"
29 * [6,6] --> "6"
30 * [8,9] --> "8->9"
31 * 
32 *  
33 * Constraints:
34 * 
35 * 	0 <= nums.length <= 20
36 * 	-2^31 <= nums[i] <= 2^31 - 1
37 * 	All the values of nums are unique.
38 * 	nums is sorted in ascending order.
39 * 
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/summary-ranges/
44// discuss: https://leetcode.com/problems/summary-ranges/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49    pub fn summary_ranges(nums: Vec<i32>) -> Vec<String> {
50        vec![]
51    }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59
60    #[test]
61    fn test_228() {
62    }
63}
64


Back
© 2025 bowen.ge All Rights Reserved.