impl Solution { fnrotate(xx: i64) ->i64 { let (mut x, mut y) = (xx, 0); while x != 0 { letmut k = x % 10; if k == 6 { k = 9; } elseif k == 9 { k = 6; } y = y * 10 + k; x = x / 10; } return y; }
fnsearch(num: i64, n: i32, ans: &muti32) { if num > n asi64 { return; } if num != 0 { if num != Self::rotate(num) { *ans += 1; } Self::search(num * 10, n, ans); } Self::search(num * 10 + 1, n, ans); Self::search(num * 10 + 6, n, ans); Self::search(num * 10 + 8, n, ans); Self::search(num * 10 + 9, n, ans); } pubfnconfusing_number_ii(n: i32) -> i32 { letmut ans = 0; Self::search(0, n, &mut ans); return ans; } }