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.

For example, the numbers "69", "88", and "818" are all strobogrammatic.

思路:写一个rotate函数,输入是0-9,输出是旋转后的数字。若旋转后不是数字,则输出一个'X'。

在主函数中,我们要检查的数字是string类型,用left和right两个指针从两端向中间逐个比较。用roate函数计算left所指的数字旋转后的结果并与right所指的数字进行比较。若不相同则为false。

class Solution {
public:
char rotate(char c) {
if (c == '')
return '';
else if (c == '')
return '';
else if (c == '' || c == '' || c == '')
return c;
else return 'X';
}
bool isStrobogrammatic(string num) {
int left = , right = num.size() - ;
while (left <= right) {
if (rotate(num[left]) != num[right])
return false;
left++;
right--;
}
return true;
}
};

Strobogrammatic Number -- LeetCode的更多相关文章

  1. [LeetCode] Strobogrammatic Number III 对称数之三

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

  2. [LeetCode] Strobogrammatic Number II 对称数之二

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

  3. [LeetCode] Strobogrammatic Number 对称数

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

  4. LeetCode Strobogrammatic Number II

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

  5. LeetCode Strobogrammatic Number

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

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

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

  7. [LeetCode] 248. Strobogrammatic Number III 对称数之三

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

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

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

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

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

随机推荐

  1. C语言中强制类型转换总结

    C语言中强制类型转换总结  ● 字符型变量的值实质上是一个8位的整数值,因此取值范围一般是-128-127,char型变量也可以加修饰符unsigned,则unsigned char 型变量的取值范围 ...

  2. linux shell 总结 (整理)

    ls /usr/bin/ info #路径操作 dirname basename #“”和‘’与 ` ` 在shell变量中的区别 “ ” 允许通过$符引用其他变量 ‘’禁止引用其他变量符,视为普通字 ...

  3. NSIS编译报错:您可能有有一个或两个(大)的旧临时文件

    一.有时在编译NSIS时会出现如下错误: 注意: 您可能有有一个或两个(大)的旧临时文件 残留在临时目录文件夹中 (通常这种情况只会发生在 Windows 9x 系统中). 二.本人遇到的问题原因: ...

  4. OpenCV_1.0安装包下载

    OpenCV_1.0安装包下载 点击下载

  5. 系统编程--文件IO

    1.文件描述符 文件描述符是一个非负整数,当打开一个现有文件或创建一个新文件时候,内核向进程返回一个文件描述符,新打开文件返回文件描述符表中未使用的最小文件描述符.Unix系统shell使用文件描述符 ...

  6. JavaWeb笔记(十)非关系型数据库Redis

    Redis Redis是一款高性能的NOSQL系列的非关系型数据库 主流的NOSQL产品 键值(Key-Value)存储数据库 相关产品: Tokyo Cabinet/Tyrant.Redis.Vol ...

  7. hadoop-hdfs(三)

    HDFS概念 1 数据块* HDFS的一个数据块默认是64M,与元数据分开管理. 优点: 数据块的大小设计的较大,所以寻址占传输的时间比例较小,只需要计算传输速度即可. 便于简化管理,利于计算剩余空间 ...

  8. intellij idea 2017 快捷键(提高工作效率)

    1.Shift+Enter Annotation annotation = c.getAnnotation(A.class); 这个时候你写代码的时候可能光标在c.getAnno中的某一个位置,那么你 ...

  9. Oracle设置用户密码永不过期

    1.查看用户的profile是那个,一般是default: select username, profile from dba_users; 2.查看指定概要文件(如default)的密码有效期设置: ...

  10. AirPlay、DLNA、Miracast三大无线技术介绍

    小米盒子之AirPlay.DLNA.Miracast三大无线技术介绍 米官方称小米盒子的米联功能可以将小米手机或iPhone.iPad上的图片.音乐.视频等精彩内容投射到电视上,让你感受大屏的刺激.而 ...