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. 练习-HTML表单

    <html lang="en"> <head> <h1>大学生爱好调查</h1> <meta charset="ut ...

  2. html5中如何去掉input type date默认样式

    html5中如何去掉input type date默认样式 1.时间选择的种类: HTML代码: 选择日期:<input type="date" value="20 ...

  3. 01 语言基础+高级:1-3 常用API第一部分_day07【Scanner类、Random类、ArrayList类】

    day07[Scanner类.Random类.ArrayList类] Scanner类Random类ArrayList类 教学目标 能够明确API的使用步骤能够使用Scanner类获得键盘录入数据能够 ...

  4. rabbitmq参考文档

    英文文档:http://www.rabbitmq.com/getstarted.html 中文文档:http://rabbitmq.mr-ping.com/ rabbitmq重启,消费者恢复,解决消费 ...

  5. 使用迅为itop4418开发板创建Android模拟器

    基于迅为iTOP-4418开发部在 Eclipse 中,单击“Windows”菜单,选择“Android Virtual Device Manager”启动 模拟器管理插件.然后如下图,单击“Crea ...

  6. Nginx模块-ngx_http_mirror_module-流量复制

    参考1:https://www.cnblogs.com/cjsblog/p/12163207.html Nginx流量复制 需求 将生产环境的流量拷贝到预上线环境或测试环境,这样做有很多好处,比如: ...

  7. Chapter2. Vector Analysis (Field and Wave Electromagnetics. Second Edition) David K. Cheng

    2-1 Introduction imperative adj.紧急的 deficiency adj. 缺点,缺乏,缺陷 awkward adj .令人尴尬的

  8. Chapter1. The Electromagnetic Model (Field and Wave Electromagnetics. Second Edition) David K. Cheng

    1-1 Introduction electric charge n.电荷 vice versa adv. 反之亦然 elastic adj. 弹性的 postulate v.假定 hasten v. ...

  9. Python文件基本操作及上下文管理

    文件基本操作 打开文件:f = open(fole_name,mode = 'r'),传入表示文件路径的字符串,会返回一个文件对象,mode是文件打开模式. 关闭文件:f.close(),调用给定文件 ...

  10. Tokyocabinet/Tokyotyrant文档大合集

    1. 前言 这里不是我个人原创,是我对网络上整理到的资料的再加工,以更成体系,更方便研究阅读.主要是对其中跟主题无关的文字删除,部分人称稍做修改;本人无版权,您可以将本页面视为对参考页面的镜像.第二部 ...