Given a string num that represents an integer, return True if num is a strobogrammatic number and False otherwise.
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
Function Signature
def is_strobogrammatic(num: str) -> bool:
Rules
-
Rotating a number by 180 degrees reverses the order of its digits and turns each digit upside down.
-
The digits 0, 1 and 8 stay the same upside down, 6 becomes 9, and 9 becomes 6. The digits 2, 3, 4, 5 and 7 are not valid digits upside down, so a string that contains any of them is not strobogrammatic.
Constraints
-
1 <= len(num) <= 50
-
num
consists only of digits.
-
num
has no leading zeros, except for
"0"
itself.
Examples
Input: num = "69"
Output: True
Rotating "69" reverses it to "96" and then flips each digit (9 becomes 6, 6 becomes 9), which gives "69" again.
Input: num = "88"
Output: True
Each 8 stays an 8 upside down, so the rotated string is "88".
Input: num = "962"
Output: False
The digit 2 has no upside-down form. The outer pair fails on its own as well: a 9 at the front would need a 6 at the end.