788. Rotated Digits Medium
1/**
2 * [788] Rotated Digits
3 *
4 * An integer x is a good if after rotating each digit individually by 180 degrees, we get a valid number that is different from x. Each digit must be rotated - we cannot choose to leave it alone.
5 * A number is valid if each digit remains a digit after rotation. For example:
6 *
7 * 0, 1, and 8 rotate to themselves,
8 * 2 and 5 rotate to each other (in this case they are rotated in a different direction, in other words, 2 or 5 gets mirrored),
9 * 6 and 9 rotate to each other, and
10 * the rest of the numbers do not rotate to any other number and become invalid.
11 *
12 * Given an integer n, return the number of good integers in the range [1, n].
13 *
14 * Example 1:
15 *
16 * Input: n = 10
17 * Output: 4
18 * Explanation: There are four good numbers in the range [1, 10] : 2, 5, 6, 9.
19 * Note that 1 and 10 are not good numbers, since they remain unchanged after rotating.
20 *
21 * Example 2:
22 *
23 * Input: n = 1
24 * Output: 0
25 *
26 * Example 3:
27 *
28 * Input: n = 2
29 * Output: 1
30 *
31 *
32 * Constraints:
33 *
34 * 1 <= n <= 10^4
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/rotated-digits/
40// discuss: https://leetcode.com/problems/rotated-digits/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn rotated_digits(n: i32) -> i32 {
46 0
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_788() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.