Practice/Meta/Leetcode 246. Strobogrammatic Number
CodingMust
A mirror number is a number that looks identical when rotated 180 degrees. When certain digits are rotated, they transform according to these rules:
All other digits (2, 3, 4, 5, 7) become invalid when rotated 180 degrees.
Given a string representing a numeric value, determine whether it qualifies as a mirror number. The number should appear identical when the entire string is rotated 180 degrees.
true if the number is a valid mirror number, false otherwisenum.length ≤ 50num consists of only digitsnum does not contain leading zeros except when the number itself is "0"Example 1:
Input: num = "69" Output: true Explanation: When rotated 180 degrees, 6 becomes 9 and 9 becomes 6. Reading the rotated result from right to left gives "69", which matches the original.
Example 2:
Input: num = "88" Output: true Explanation: Each 8 remains an 8 when rotated. The number reads the same after rotation.
Example 3:
Input: num = "962" Output: false Explanation: The digit 2 cannot be rotated to form a valid digit, so this is not a mirror number.
Example 4:
Input: num = "1" Output: true Explanation: The digit 1 looks the same when rotated 180 degrees.