20240513 Finished
This commit is contained in:
		@@ -130,3 +130,4 @@ mod p49_group_anagrams;
 | 
			
		||||
mod p202_happy_number;
 | 
			
		||||
mod p219_contains_duplicate_ii;
 | 
			
		||||
mod p128_longest_consecutive_sequence;
 | 
			
		||||
mod p228_summary_ranges;
 | 
			
		||||
@@ -4,7 +4,7 @@
 | 
			
		||||
pub struct Solution {}
 | 
			
		||||
 | 
			
		||||
// submission codes start here
 | 
			
		||||
use std::{collections::HashSet, ops::Add};
 | 
			
		||||
use std::collections::HashSet;
 | 
			
		||||
 | 
			
		||||
impl Solution {
 | 
			
		||||
    pub fn is_happy(n: i32) -> bool {
 | 
			
		||||
@@ -13,7 +13,6 @@ impl Solution {
 | 
			
		||||
        let mut n = Solution::calculate_square(n);
 | 
			
		||||
 | 
			
		||||
        while n != 1 {
 | 
			
		||||
            dbg!(n);
 | 
			
		||||
            if s.contains(&n) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										54
									
								
								src/problem/p228_summary_ranges.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								src/problem/p228_summary_ranges.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,54 @@
 | 
			
		||||
/**
 | 
			
		||||
 * [228] Summary Ranges
 | 
			
		||||
 */
 | 
			
		||||
pub struct Solution {}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// submission codes start here
 | 
			
		||||
 | 
			
		||||
impl Solution {
 | 
			
		||||
    pub fn summary_ranges(nums: Vec<i32>) -> Vec<String> {
 | 
			
		||||
        let mut result = vec![];
 | 
			
		||||
 | 
			
		||||
        if nums.len() == 0 {
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        let mut begin = nums[0];
 | 
			
		||||
        let mut end = nums[0];
 | 
			
		||||
 | 
			
		||||
        for i in 1..nums.len() {
 | 
			
		||||
            if nums[i] == end + 1 {
 | 
			
		||||
                end += 1;
 | 
			
		||||
            } else {
 | 
			
		||||
                result.push(if begin == end {
 | 
			
		||||
                    format!("{}", begin)
 | 
			
		||||
                } else {
 | 
			
		||||
                    format!("{}->{}", begin, end)
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
                begin = nums[i];
 | 
			
		||||
                end = nums[i];
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        result.push(if begin == end {
 | 
			
		||||
            format!("{}", begin)
 | 
			
		||||
        } else {
 | 
			
		||||
            format!("{}->{}", begin, end)
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        result
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// submission codes end
 | 
			
		||||
 | 
			
		||||
#[cfg(test)]
 | 
			
		||||
mod tests {
 | 
			
		||||
    use super::*;
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn test_228() {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user