博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[LeetCode] Strobogrammatic Number
阅读量:5267 次
发布时间:2019-06-14

本文共 1112 字,大约阅读时间需要 3 分钟。

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
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 };

 

转载于:https://www.cnblogs.com/jcliBlogger/p/4708243.html

你可能感兴趣的文章
ANT打包J2EE项目war包
查看>>
UESTC-我要长高 DP优化
查看>>
java选择文件时提供图像缩略图[转]
查看>>
当DIV内出现滚动条,fixed实效怎么办?
查看>>
方维分享系统二次开发, 给评论、主题、回复、活动 加审核的功能
查看>>
Matlab parfor-loop并行运算
查看>>
string与stringbuilder的区别
查看>>
2012-01-12 16:01 hibernate注解以及简单实例
查看>>
iOS8统一的系统提示控件——UIAlertController
查看>>
PAT甲级——1101 Quick Sort (快速排序)
查看>>
python创建进程的两种方式
查看>>
1.2 基础知识——关于猪皮(GP,Generic Practice)
查看>>
迭代器Iterator
查看>>
java易错题----静态方法的调用
查看>>
php建立MySQL数据表
查看>>
最简单的线程同步的例子
查看>>
JSP、Servlet乱码终极解决方案
查看>>
旅途上看的电影和观后感
查看>>
qt实现类似QQ伸缩窗口--鼠标事件应用
查看>>
Ztree异步树加载
查看>>