All problems
Strobogrammatic Number Check
Problem
Return True if the digit string looks the same when rotated 180 degrees, and False otherwise.
Only 0, 1, 6, 8 and 9 remain valid digits after rotation, with 6 and 9 swapping and the others fixed. Compare characters from the two ends; the empty string is considered valid.
Hint
The pair check simultaneously validates the middle character when the length is odd.
Test cases
case 1
in: ["69"]
expected: true
case 2
in: ["88"]
expected: true
case 3
in: ["962"]
expected: false
case 4
in: ["609"]
expected: true
case 5
in: [""]
expected: true
case 6
in: ["2"]
expected: false
Starter codePython
def is_strobogrammatic(s):
# Your code here
pass6 test cases · run your code against them in the editor