20250411 finished.
This commit is contained in:
		| @@ -591,3 +591,5 @@ mod p3396_minimum_number_of_operations_to_make_elements_in_array_distinct; | |||||||
|  |  | ||||||
| mod p2999_count_the_number_of_powerful_integers; | mod p2999_count_the_number_of_powerful_integers; | ||||||
| mod p3375_minimum_operations_to_make_array_values_equal_to_k; | mod p3375_minimum_operations_to_make_array_values_equal_to_k; | ||||||
|  |  | ||||||
|  | mod p2843_count_symmetric_integers; | ||||||
|   | |||||||
							
								
								
									
										42
									
								
								src/problem/p2843_count_symmetric_integers.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								src/problem/p2843_count_symmetric_integers.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | |||||||
|  | /** | ||||||
|  |  * [2843]   Count Symmetric Integers | ||||||
|  |  */ | ||||||
|  | pub struct Solution {} | ||||||
|  |  | ||||||
|  | // submission codes start here | ||||||
|  |  | ||||||
|  | impl Solution { | ||||||
|  |     pub fn count_symmetric_integers(low: i32, high: i32) -> i32 { | ||||||
|  |         // 10 -> 99 1000 -> 9999 | ||||||
|  |         (low..=high) | ||||||
|  |             .filter_map(|i| { | ||||||
|  |                 if i >= 10 && i <= 99 { | ||||||
|  |                     if i / 10 == i % 10 { | ||||||
|  |                         return Some(()); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 if i >= 1000 && i <= 9999 { | ||||||
|  |                     if i / 1000 + (i / 100) % 10 == (i / 10) % 10 + i % 10 { | ||||||
|  |                         return Some(()); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 None | ||||||
|  |             }) | ||||||
|  |             .count() as i32 | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // submission codes end | ||||||
|  |  | ||||||
|  | #[cfg(test)] | ||||||
|  | mod tests { | ||||||
|  |     use super::*; | ||||||
|  |  | ||||||
|  |     #[test] | ||||||
|  |     fn test_2843() { | ||||||
|  |         assert_eq!(9, Solution::count_symmetric_integers(1, 99)); | ||||||
|  |         assert_eq!(4, Solution::count_symmetric_integers(1200, 1230)); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user