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.


题目标签:Hash Table
 
  题目给了我们一个string num,让我们判断是不是 可翻转180°的数字。
 
  在数字里,可以颠倒的数字有:0,1,6,9,8  在这些数字中,69 是特殊的一对,剩下的数字颠倒后依然是原样。
 
  只要把这些存入HashMap就可以了。
 
 
 

Java Solution:

Runtime beats 11.67%

完成日期:05/27/2017

关键词:HashMap

关键点:利用HashMap来存入0 - 0, 1 - 1, 6 - 9, 9 - 6, 8 - 8

 class Solution
{
public boolean isStrobogrammatic(String num)
{
HashMap<Character, Character> map = new HashMap<>(); map.put('1','1');
map.put('6','9');
map.put('9','6');
map.put('8','8');
map.put('0','0'); char[] arr = num.toCharArray();
int left = 0;
int right = arr.length - 1; while(left <= right)
{
if(!map.containsKey(arr[left]) || map.get(arr[left]) != arr[right])
return false; left++;
right--;
} return true; }
}

参考资料:N/A

LeetCode 题目列表 - LeetCode Questions List

最新文章

  1. MySQL高级查询语句
  2. Django-安装篇
  3. JavaOne 2016——观众得以一睹JShell的威力
  4. 2015年9月28日JQuery提前预习预热笔记
  5. 3行3列表格 table实现,div+css实现
  6. 导入Excel加行公式和验证
  7. 部署DNS服务
  8. Android常用布局、文件存储与权限、XML
  9. Python s12 Day3 笔记及作业
  10. Linux多线程实践(三)线程的基本属性设置API
  11. hdu 1255 覆盖的面积(求覆盖至少两次以上的面积)
  12. [20190416]process allocation latch.txt
  13. 红黑树(red-black tree)实现记录
  14. 解决Tomcat启动时项目重复加载问题
  15. gf框架之grpool - 高性能的goroutine池
  16. Asp.Net MVC Razor视图引擎与My97DatePicker插件的结合
  17. MVC MVP MVVM 图解
  18. golang 垃圾回收 gc
  19. APP测试功能点总结
  20. Linux 基础教程 41-系统关机和重启

热门文章

  1. C++(Typedef声明)
  2. NVIDIA各个领域芯片现阶段的性能和适应范围
  3. 如何在mybatis中引用java中的常量和方法
  4. CodeFrist基础_Fluent Api
  5. 批量生成随机字符串并保存到excel
  6. 【webpack插件使用】在开发中快速掌握并使用Webpack构建web应用程序
  7. Extjs选中多行Grid提交
  8. 洛谷——P2261 [CQOI2007]余数求和
  9. Redis多实例配置以及主从同步
  10. linux hexdump-显示文件十六进制格式