> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Strobogrammatic Number Python Solution

> Tested Python solution for LeetCode 246 with 18 pytest cases. Generate a practice environment with lcpy.

LeetCode 246, [Easy](/catalog/easy). Topics: [Hash Table](/catalog/topics/hash-table), [Two Pointers](/catalog/topics/two-pointers), [String](/catalog/topics/string). [View on LeetCode](https://leetcode.com/problems/strobogrammatic-number/description/).

Generate this problem as a practice environment: tested reference solution, 18 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 246   # by problem number
lcpy gen -s strobogrammatic_number   # by problem name
```

## Problem

Given a string `num` which represents an integer, return `true` *if* `num` *is a **strobogrammatic number***.

A **strobogrammatic number** is a number that looks the same when rotated `180` degrees (looked at upside down).

### Examples

```
Input: num = "69"
Output: true
```

```
Input: num = "88"
Output: true
```

```
Input: num = "962"
Output: false
```

### Constraints

* `1 <= num.length <= 50`
* `num` consists of only digits.
* `num` does not contain any leading zeros except for zero itself.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/strobogrammatic_number/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/strobogrammatic_number/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n)
    # Space: O(1)
    def is_strobogrammatic(self, num: str) -> bool:
        rotated = {"0": "0", "1": "1", "8": "8", "6": "9", "9": "6"}
        left = 0
        right = len(num) - 1
        while left <= right:
            if num[left] not in rotated or rotated[num[left]] != num[right]:
                return False
            left += 1
            right -= 1
        return True
```

## Complexity

| Time | Space |
| - | - |
| O(n) | O(1) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.