Skip to main content

Count Numbers with Unique Digits

打表题,优化一下表就是O1 & O1

impl Solution {    pub fn count_numbers_with_unique_digits(n: i32) -> i32 {        use std::convert::TryInto;        let n: usize = n.try_into().unwrap();        let arr = [0, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3265920];        let mut res = 0;        for i in 0..=n {            res += arr[10] / arr[10 - i];        }        res    }}