Separate the Numbers

  • + 0 comments

    My rust solution:

    fn separateNumbers(s: &str) {
        let mut i = 0;
        'main: while i < s.len() / 2 {
            i += 1;
            let x: i64 = s[..i].parse().unwrap();
            
            let mut next = (x + 1).to_string();
            if s[i..(i + next.len())] == next {
                let mut tmp = &s[(i + next.len())..];
                while !tmp.is_empty() {
                    next = (next.parse::<i64>().unwrap() + 1).to_string();
                    if &tmp[..next.len().min(tmp.len())] != next {
                        continue 'main;
                    }
                    tmp = &tmp[next.len()..];
                }
                println!("YES {x}");
                return;
            }
        }
        println!("NO");