判断String是否为palindrome:Two Pointers(left & right) 同时边扫边check 当前两边的char是否相同

code

 public boolean isValidPalindrome(String s){
int l = 0;
int r = s.length() - 1;
while (l < r){
if(s.charAt(l) != s.charAt(r)){
return false;
}else{
l++;
r--;
}
}
return true;
}

判断number是否为palindrome:先reverse original number 变为reversed number ,再判断 original number == reversed number ?

code

     public boolean isPalindrome(int x) {
// handle input is negative like -121 or end with 0
if (x < 0 || (x != 0 && x % 10 == 0)) return false; int temp = x;
int reverseInt = 0;
while (x != 0) {
reverseInt = reverseInt * 10 + x % 10;
x = x / 10;
}
return (reverseInt == temp);
}

对palindrome的常用判断的更多相关文章

  1. SQL 常用判断语句

    我们在做sql更新时,为防止sql重复执行报错,需要对所需要执行的对象进行判断是否存在: 常用判断脚本如下: 判断视图是否存在 IF object_id('viewname') IS not NULL ...

  2. 2019-11-29-msbuild-项目文件常用判断条件

    title author date CreateTime categories msbuild 项目文件常用判断条件 lindexi 2019-11-29 08:36:48 +0800 2019-7- ...

  3. 2019-8-31-msbuild-项目文件常用判断条件

    title author date CreateTime categories msbuild 项目文件常用判断条件 lindexi 2019-08-31 16:55:59 +0800 2019-7- ...

  4. String类的常用判断方法使用练习

    选取了一些常用的判断方法进行了使用练习,后续跟新其他方法 package StringDemo; // String类的判断方法解析 // 1:boolean equals(); // 判断字符串是否 ...

  5. php常用判断的函数

    empty($var)        //用来检查变量是否为空(没有值或零值) isset($var)           //这个//测试一个变量看它是否已被定义. gettype($var)   ...

  6. leetcode:Palindrome Number (判断数字是否回文串) 【面试算法题】

    题目: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could neg ...

  7. 234. Palindrome Linked List(判断链表是否回文)

    Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O(n) time ...

  8. Python 字符串常用判断函数

    判断字符串常用函数: S代表某字符串 S.isalnum()  所有字符都是数字或字母,为真返回Ture,否则返回False S.isalha()     所有字符都是字母,为真返回Ture,否则返回 ...

  9. javascript常用判断写法

    js验证表单大全,用JS控制表单提交 ,javascript提交表单 目录:1:js 字符串长度限制.判断字符长度 .js限制输入.限制不能输入.textarea 长度限制 2.:js判断汉字.判断是 ...

随机推荐

  1. Centos7下GlusterFS 分布式文件系统环境搭建

    Centos7下 GlusterFS 环境搭建准备工作glusterfs-3.6.9.tar.gzuserspace-rcu-master.zip三台服务器:192.168.133.53.192.16 ...

  2. BAT开发中,ChromeDriver版本兼容性检查

    打开解决方案的Nuget包管理器,选择合适的版本,安装即可.版本的兼容性检查,见上一篇blog(初次使用BAT,请检查Chrome浏览器和ChromeDriver兼容性 https://www.cnb ...

  3. 安装Git Bash图文教程

    1.下载Git Bash,下载地址 https://pan.baidu.com/s/1sllsi0d 2.双击Git-2.9.2-64-bit.exe,运行,进行安装:点击“Next” 3.设置安装路 ...

  4. C#,ASP.NET简单的MD5加密,解密

    简单的MD5加密 首先要有一个加解密的规则  就是key 代码如下 // 创建Key public string GenerateKey() { DESCryptoServiceProvider de ...

  5. golang初识 - install go on ubuntu

    WSL: Ubuntu 18.04 1. install go (1) unzip sudo mkdir -p /usr/local/go sudo tar zxvf go1.12.4.linux-a ...

  6. https://www.oschina.net/project/lang/19/java

    https://www.oschina.net/project/lang/19/java

  7. JAVA发送HttpClient请求及接收请求结果

    1.写一个HttpRequestUtils工具类,包括post请求和get请求 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2 ...

  8. android studio 运行项目时waiting for target device to come online

    cmd进入命令行,进入adb所在的目录下: 或者在Terminal中输入命令: adb kill-server adb start-server

  9. [python爬虫] Selenium常见元素定位方法和操作的学习介绍

    这篇文章主要Selenium+Python自动测试或爬虫中的常见定位方法.鼠标操作.键盘操作介绍,希望该篇基础性文章对你有所帮助,如果有错误或不足之处,请海涵~同时CSDN总是屏蔽这篇文章,再加上最近 ...

  10. gitlab api 使用

    api文档:https://docs.gitlab.com/ee/api/projects.html#project-visibility-level 1.项目查询 http://127.0.0.1: ...