Strobogrammatic Number
Real-world version: Does the Reading Survive a Half TurnThe statement here is our own: the same inputs, outputs and technique.
A reading is given as the string num, made only of digits.
Turning the whole reading upside down turns each digit in place and reverses their order. Only some digits survive the turn: 0, 1 and 8 turn into themselves, while 6 and 9 turn into each other. Every other digit becomes unreadable.
Return whether the reading looks exactly the same after being turned upside down.
Examples
Example 1
- Input
- num = "1961"
- Output
- true
The outer ones turn into each other, and the nine and six in the middle swap into each other, so the turned reading matches the original.
Example 2
- Input
- num = "25"
- Output
- false
The two has no turned form at all, so the reading cannot survive.
Example 3
- Input
- num = "0"
- Output
- true
A single zero turns into itself, so the reading is unchanged.
Constraints
- 1 <= num.length <= 50
- The reading is made of digits only.
- The reading has no leading zero unless it is the single digit zero.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def is_strobogrammatic(num: str) -> bool:public boolean isStrobogrammatic(String num)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's