> For the complete documentation index, see [llms.txt](https://jimmylin1991.gitbook.io/practice-of-algorithm-problems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jimmylin1991.gitbook.io/practice-of-algorithm-problems/math/246.-strobogrammatic-number.md).

# 246. Strobogrammatic Number

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

Write a function to determine if a number is strobogrammatic. The number is represented as a string.

**Example 1:**

```
Input:  "69"
Output: true
```

**Example 2:**

```
Input:  "88"
Output: true
```

**Example 3:**

```
Input:  "962"
Output: false
```

```cpp
bool isStrobogrammatic(string num) { // time: O(n); space: O(1)
    string rotate(10, ' ');
    rotate['0' - '0'] = '0';
    rotate['1' - '0'] = '1';
    rotate['6' - '0'] = '9';
    rotate['8' - '0'] = '8';
    rotate['9' - '0'] = '6';
    int l = 0, r = num.length() - 1;
    while (l <= r) {
        if (rotate[num[l] - '0'] != num[r]) return false;
        ++l, --r;
    }
    return true;
}
```

```cpp
bool isStrobogrammatic(string num) { // time: O(n); space: O(1)
    const string pattern = "00 11 88 696";
    string search;
    for (int i = 0, j = num.length() - 1; i <= j; ++i, --j) {
        search.clear();
        search.push_back(num[i]);
        search.push_back(num[j]);
        if (pattern.find(search) == string::npos) return false;
    }
    return true;
}
```
