From b8cc12db71ffa5d2b84649894312fb528f57e608 Mon Sep 17 00:00:00 2001 From: li-chx Date: Fri, 24 Oct 2025 08:40:05 +0800 Subject: [PATCH] =?UTF-8?q?2048.=20=E4=B8=8B=E4=B8=80=E4=B8=AA=E6=9B=B4?= =?UTF-8?q?=E5=A4=A7=E7=9A=84=E6=95=B0=E5=80=BC=E5=B9=B3=E8=A1=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 847a055..1b98a41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,22 +2,14 @@ mod arr; struct Solution {} impl Solution { - pub fn has_same_digits(s: String) -> bool { - let n = s.len() - 2; - let s = s.chars().collect::>(); - let (mut p1,mut p2) = (0,0); - let mut base = 1_u128; - let mut k = 0; - for i in 0..=n { - p1 += base * (s[i].to_digit(10).unwrap() as u128); - p2 += base * (s[i+1].to_digit(10).unwrap() as u128); - base = base * (n as u128 - k) / (k+1); - k+=1; - } - p1 % 10 == p2 % 10 + pub fn next_beautiful_number(n: i32) -> i32 { + let arr = vec![ 0,1,22,122,212,221,333,1333,3133,3313,3331,4444,14444,22333,23233,23323,23332,32233,32323,32332,33223,33232,33322,41444,44144,44414,44441,55555,122333,123233,123323,123332,132233,132323,132332,133223,133232,133322,155555,212333,213233,213323,213332,221333,223133,223313,223331,224444,231233,231323,231332,232133,232313,232331,233123,233132,233213,233231,233312,233321,242444,244244,244424,244442,312233,312323,312332,313223,313232,313322,321233,321323,321332,322133,322313,322331,323123,323132,323213,323231,323312,323321,331223,331232,331322,332123,332132,332213,332231,332312,332321,333122,333212,333221,422444,424244,424424,424442,442244,442424,442442,444224,444242,444422,515555,551555,555155,555515,555551,666666,1224444 ]; + let point = arr.partition_point(|v| v <= &n); + arr[point] + } } fn main() { - println!("{:?}", Solution::has_same_digits("50656587913386788475086249545073".to_string())); + println!("{:?}", Solution::next_beautiful_number(1333)); }