Size: 676 bytes.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3
# cs/q/strobogrammatic/solution.py
# Leetcode 246: Strobogrammatic Number
# https://leetcode.com/problems/strobogrammatic-number/

LOOKUP = {"0": "0", "1": "1", "6": "9", "8": "8", "9": "6"}


def IsStrobogrammatic(num: str) -> bool:
    if not num:
        return False
    if len(num) > 1 and num[0] == "0":
        return False
    i = 0
    j = len(num) - 1
    while i <= j:
        if num[i] not in LOOKUP:
            return False
        if LOOKUP[num[i]] != num[j]:
            return False
        i += 1
        j -= 1
    return True


class Solution:
    def isStrobogrammatic(self, num: str) -> bool:
        return IsStrobogrammatic(num)
v0 (commit) © 2025 @p13i.io | Load balancer proxied to: cs-code-viewer-3:8080 in 4ms.