[LC] 246. Strobogrammatic Number
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的更多相关文章
- 246. Strobogrammatic Number 上下对称的数字
[抄题]: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at u ...
- 246. Strobogrammatic Number
题目: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at ups ...
- LeetCode 246. Strobogrammatic Number (可颠倒数字) $
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...
- [LeetCode] 246. Strobogrammatic Number 对称数
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...
- LeetCode 246. Strobogrammatic Number
原题链接在这里:https://leetcode.com/problems/strobogrammatic-number/ 题目: A strobogrammatic number is a numb ...
- 【LeetCode】246. Strobogrammatic Number 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcode ...
- [LeetCode] 247. Strobogrammatic Number II 对称数II
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...
- [LeetCode] 248. Strobogrammatic Number III 对称数III
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...
- [LeetCode#246] Missing Ranges Strobogrammatic Number
Problem: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked a ...
随机推荐
- Java--二维码生成&图片和流转化
package test; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java. ...
- 移动端— Touch事件轮播图
虽然 以前也写过手机端页面 .当时用的jquery moblie 框架.啥也不懂 就知道复制粘贴出效果 不敢改内部样式.现在呢 了解手机端原理 一些基本的概念 视口 缩放 后 .再去想以前写的页面 ...
- subprocess.Popen stdout重定向内容实时获取
python 打开一个新进程执行系统命令, test 执行完才能获取返回, test1 实时获取返回结果 import subprocess def test(cmd): p = subprocess ...
- MySQL-慢日志slow log
文件结构 1.目录结构 drwxrwxr-x mysql mysql Mar bin drwxrwxr-x mysql mysql Dec : binlogdir -rw-r--r-- mysql m ...
- P3810 【模板】三维偏序(陌上花开)(CDQ分治)
题目背景 这是一道模板题 可以使用bitset,CDQ分治,K-DTree等方式解决. 题目描述 有 nn 个元素,第 ii 个元素有 a_iai.b_ibi.c_ici 三个属性,设 f(i) ...
- Docker 三剑客--Machine
Machine 我们知道在多个集群服务环境下,安装管理Docker的容器,要使用的是Docker Swarm,而使用Docker Swarm的情况是在多个集群的服务器已经搭建好Docker环境的情况下 ...
- Linux进程的引入
1.什么是进程? (1).进程是一个动态过程而不是静态实物 (2).进程就是程序的一次运行过程,一个静态的可执行程序a.out的一次运行过程(./a.out从运行到结束)就是一个进程. (3).进程控 ...
- Dinic学习笔记
网络流是啥不用我说了吧 增广路定理不用我说了吧 Dinic就是分层然后只在层间转移,然后就特别快,\[O(N^2M)\] 伪代码: function dinic int flow = 0 ; whil ...
- h5 移动端在阻止touchstart的默认事件时报错
h5 移动端在阻止touchstart的默认事件时报错 解决办法, 可以添加 *{ touch-action: none;}即可消除错误
- goweb-安装go及配置go
安装go及配置go 安装go 写这篇博客时,我的电脑的windows已经安装过了go,用的是标准包安装,不过我的linux操作系统还没安装,可以考虑用第三方工具安装,因为看了goweb这本书,我才知道 ...