# [LeetCode] Strobogrammatic Number

Problem Description:

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.

For example, the numbers "69", "88", and "818" are all strobogrammatic.

The following is the C++ implementation of the suggested solution using a look-up table (implemented as an unordered_map). It takes 0 ms. But, I wonder, are there any real applications of strobogrammatic numbers?

 1 class Solution {
2 public:
3     bool isStrobogrammatic(string num) {
4         make_lut();
5         int n = num.length();
6         for (int l = 0, r = n - 1; l <= r; l++, r--)
7             if (lut.find(num[l]) == lut.end() || lut[num[l]] != num[r])
8                 return false;
9         return true;
10     }
11 private:
12     unordered_map<char, char> lut;
13     void make_lut(void) {
14         lut['0'] = '0';
15         lut['1'] = '1';
16         lut['6'] = '9';
17         lut['8'] = '8';
18         lut['9'] = '6';
19     }
20 };

|
9月前
|

Leetcode 313. Super Ugly Number

82 1
|
2月前
|

LeetCode 题目 65：有效数字（Valid Number）【python】
LeetCode 题目 65：有效数字（Valid Number）【python】
37 5
|
3月前
|

【LeetCode力扣】单调栈解决Next Greater Number（下一个更大值）问题
【LeetCode力扣】单调栈解决Next Greater Number（下一个更大值）问题
25 0
|
9月前
|

Leetcode Single Number II （面试题推荐）

30 0
|

LeetCode contest 190 5417. 定长子串中元音的最大数目 Maximum Number of Vowels in a Substring of Given Length
LeetCode contest 190 5417. 定长子串中元音的最大数目 Maximum Number of Vowels in a Substring of Given Length
102 0
LeetCode Contest 178-1365. 有多少小于当前数字的数字 How Many Numbers Are Smaller Than the Current Number
LeetCode Contest 178-1365. 有多少小于当前数字的数字 How Many Numbers Are Smaller Than the Current Number
82 0
|

LeetCode 136. 只出现一次的数字 Single Number
LeetCode 136. 只出现一次的数字 Single Number
57 0
LeetCode contest 177 5169. 日期之间隔几天 Number of Days Between Two Dates
LeetCode contest 177 5169. 日期之间隔几天 Number of Days Between Two Dates
89 0
|
8天前
|
Python
【Leetcode刷题Python】剑指 Offer 32 - III. 从上到下打印二叉树 III

20 6
|
8天前
|

【Leetcode刷题Python】牛客. 数组中未出现的最小正整数

23 2