[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反射--getDeclaredField()和getField()
Field getField(String name) 返回当前类以及所继承的类的所有public修饰的成员变量 Field getDeclaredField(String name) 返 ...
- 系统学习python第五天学习笔记
1.列表补充 extend() li = ["alex", "WuSir", "ritian", "barry", &q ...
- JavaScript sort()方法总结
sort() 方法用于对数组的元素进行排序. 语法:arrayObject.sort(sortby):参数sortby可选.规定排序顺序.必须是函数. 注:如果调用该方法时没有使用参数,将按字母顺序对 ...
- 给锚点a标签添加滑动效果
a标签是前端必用之一,但是a标签点击后马上跳到了href属性值处,有时候要达到滑动效果就要自己添加JavaScript 普通的a标签代码写好之后,在js脚本内加上 $("a").c ...
- array_flip() 函数返回一个反转后的数组
定义和用法 array_flip() 函数返回一个反转后的数组,如果同一值出现了多次,则最后一个键名将作为它的值,所有其他的键名都将丢失. 如果原数组中的值的数据类型不是字符串或整数,函数将报错 ar ...
- java EE应用概述
1.javaEE应用的分层模型 不管是经典的Java EE架构,还是轻量级的Java EE架构,大致上都可以分为以下几层: Damain Object(领域对象)层:该层是由系列的POJO(普通的,传 ...
- 吴裕雄--天生自然ShellX学习笔记:Shell test 命令
Shell中的 test 命令用于检查某个条件是否成立,它可以进行数值.字符和文件三个方面的测试. 实例演示: num1=100 num2=100 if test $[num1] -eq $[num2 ...
- JavaSE--数字签名之校验签名
参考:http://blog.csdn.net/dotuian/article/details/51722300 关于keystore的简单介绍 Keytool是一个Java数据证书的管理工具 ,Ke ...
- centos 从头部署java环境
1.首先安装lrzsz 上传下载服务 yum install -y lrzsz 2.然后检查是否已经安装java rpm -qa|grep java 如果已经安装卸载后再重新安装 3.将下载好的jdk ...
- Adaboost算法及其代码实现
. . Adaboost算法及其代码实现 算法概述 AdaBoost(adaptive boosting),即自适应提升算法. Boosting 是一类算法的总称,这类算法的特点是通过训练若干弱分类器 ...