[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 ...
随机推荐
- iOS 蓝牙开发详解
目前iOS智能硬件的开发交互方式主要分为两种,一种是基于低功耗的蓝牙4.0技术(由于耗电低,也称作为BLE(Bluetooth Low Energy))对应iOS的框架为CoreBluetooth,另 ...
- awk使用笔记
awk特殊字符打印方法: 1.awk打印双引号: awk '{print "\""}' 2.awk打印单引号: awk '{print "'\''&quo ...
- Android studio个人常用快捷键
个人常用重点: 电脑模式不一样需要加上fn键进行切换 Alt+回车/Enter 导入包,实现接口的方法.自动修正 Ctrl+X 删除行 Ctrl+D 复制行 Ctrl+Shift+Space 自动补 ...
- 计算机网络(3): ICMP报文
- 基础练习--huffman
问题描述 Huffman树在编码中有着广泛的应用.在这里,我们只关心Huffman树的构造过程. 给出一列数{pi}={p0, p1, …, pn-},用这列数构造Huffman树的过程如下: . 找 ...
- Android studio中2种build.gradle文件介绍
根目录下的build.gradle通常不需要修改这个文件中的内容,除非需要添加一些全局的项目构建配置 buildscript { repositories { google() //声明代码托管仓库G ...
- vue中在时间输入框中默认显示时间
<template> <card> <label>开始时间</label> <DatePicker v-model="startTime ...
- 17.3.12---logging日志模块level配置操作
1----logging日志记录模块的使用和配置 logging模块我们不需要单独再安装,经常要调试程序,记录程序运行过程中的一些信息,手工记录调试信息很麻烦,所以python的logging模块,会 ...
- 远程调用shell脚本文件和远程复制文件
1.安装sshpass yum install sshpass 2.本地调用远程服务器的shell脚本文件: sshpass -p sa ssh root@192.168.56.105 -C &quo ...
- goweb-处理静态资源
处理静态文件 对于 HTML 页面中的 css 以及 js 等静态文件,需要使用使用 net/http 包下的以下 方法来处理 1) StripPrefix 函数 2) FileServer 函数 3 ...