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
class Solution {
public boolean isStrobogrammatic(String num) {
Map<Character, Character> mymap = new HashMap<>();
mymap.put('1', '1');
mymap.put('8', '8');
mymap.put('0', '0');
mymap.put('6', '9');
mymap.put('9', '6');
int left = 0;
int right = num.length() - 1;
while (left <= right) {
char left_char = num.charAt(left);
char right_char = num.charAt(right);
if (!mymap.containsKey(left_char) || !mymap.containsKey(right_char)) {
return false;
} else if (mymap.get(left_char) != right_char) {
return false;
}
left += 1;
right -= 1;
}
return true;
}
}

[LC] 246. Strobogrammatic Number的更多相关文章

  1. 246. Strobogrammatic Number 上下对称的数字

    [抄题]: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at u ...

  2. 246. Strobogrammatic Number

    题目: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at ups ...

  3. LeetCode 246. Strobogrammatic Number (可颠倒数字) $

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

  4. [LeetCode] 246. Strobogrammatic Number 对称数

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

  5. LeetCode 246. Strobogrammatic Number

    原题链接在这里:https://leetcode.com/problems/strobogrammatic-number/ 题目: A strobogrammatic number is a numb ...

  6. 【LeetCode】246. Strobogrammatic Number 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcode ...

  7. [LeetCode] 247. Strobogrammatic Number II 对称数II

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

  8. [LeetCode] 248. Strobogrammatic Number III 对称数III

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

  9. [LeetCode#246] Missing Ranges Strobogrammatic Number

    Problem: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked a ...

随机推荐

  1. ccs-基础-阴影

    1.html代码 <div class="demo demo1">假如生活欺骗了你</div> <div class="demo demo2 ...

  2. php速成_day3

    一.MySQL关系型数据库 1.什么是数据库 数据库 数据存储的仓库,在网站开发应用当中,需要有一些数据存储起来. 注册的用户信息,使用PHP变量只是一个临时的存储,如果需要永久的存储起来,就把数据存 ...

  3. Python3中bytes和HexStr之间的转换

    1 Python3中bytes和HexStr之间的转换 ByteToHex的转换 def ByteToHex( bins ): """ Convert a byte st ...

  4. Java线程——线程习题(一)子线程执行10次后,主线程再运行5次,这样交替执行三遍

    题目:子线程执行10次后,主线程再运行5次,这样交替执行三遍 代码如下: package com.itheima.gan; /** * 子线程执行10次后,主线程再运行5次,这样交替执行三遍 * @a ...

  5. 2018.11.2JavaScript随笔

    构造函数首字母大写 通过new创建对象 BOM:浏览器对象模型

  6. c# 异常处理 try --catch

    初学 try---catch 语法 try { 可能会出现异常的代码; 异常出现的那行代码下面的代码全不会执行,直接跳到catch中执行 ... ... } //try和catch之间不能有其他的代码 ...

  7. ZJNU 2133 - 认亲大会

    将辈分差距转为数字 例如 A 是 B son A=B-1 A 是 B grandfather A=B+2然后编号1数字设置为0,建图bfs 最后搜索编号2到100是否存在>0的数即可 /* Wr ...

  8. JS - ES5与ES6面向对象编程

    1.面向对象 1.1 两大编程思想 1.2 面向过程编程 POP(Process-oriented programming) 1.3 面向对象编程 OOP (Object Oriented Progr ...

  9. docker安装文档

    Docker离线安装以及本地yum源构建http://blog.csdn.net/joniers/article/details/64122820http://blog.csdn.net/wsscy2 ...

  10. ID3/C4.5/Gini Index

    ID3/C4.5/Gini Index */--> ID3/C4.5/Gini Index 1 ID3 Select the attribute with the highest informa ...