对palindrome的常用判断
判断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的常用判断的更多相关文章
- SQL 常用判断语句
我们在做sql更新时,为防止sql重复执行报错,需要对所需要执行的对象进行判断是否存在: 常用判断脚本如下: 判断视图是否存在 IF object_id('viewname') IS not NULL ...
- 2019-11-29-msbuild-项目文件常用判断条件
title author date CreateTime categories msbuild 项目文件常用判断条件 lindexi 2019-11-29 08:36:48 +0800 2019-7- ...
- 2019-8-31-msbuild-项目文件常用判断条件
title author date CreateTime categories msbuild 项目文件常用判断条件 lindexi 2019-08-31 16:55:59 +0800 2019-7- ...
- String类的常用判断方法使用练习
选取了一些常用的判断方法进行了使用练习,后续跟新其他方法 package StringDemo; // String类的判断方法解析 // 1:boolean equals(); // 判断字符串是否 ...
- php常用判断的函数
empty($var) //用来检查变量是否为空(没有值或零值) isset($var) //这个//测试一个变量看它是否已被定义. gettype($var) ...
- leetcode:Palindrome Number (判断数字是否回文串) 【面试算法题】
题目: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could neg ...
- 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 ...
- Python 字符串常用判断函数
判断字符串常用函数: S代表某字符串 S.isalnum() 所有字符都是数字或字母,为真返回Ture,否则返回False S.isalha() 所有字符都是字母,为真返回Ture,否则返回 ...
- javascript常用判断写法
js验证表单大全,用JS控制表单提交 ,javascript提交表单 目录:1:js 字符串长度限制.判断字符长度 .js限制输入.限制不能输入.textarea 长度限制 2.:js判断汉字.判断是 ...
随机推荐
- 设置 P2415Q & P2715Q 显示器使其支持 HDMI 2.0 启用 4k@60hz
简介:2016 年 2 月后购买的 Dell P2415Q 和 P2715Q 显示器,支持 HDMI 2.0,但是默认启用的是 HDMI 1.4. HDMI 2.0 默认没有启用 Dell P2415 ...
- iptables的MAC地址过滤
这里(http://en.wikipedia.org/wiki/Mac_address)有关于MAC地址的一些信息. 查询现有设置 iptables -S [chain] 比如:针对1中所设 inp ...
- C# & JAVA:读写文件
using System; using System.IO; using System.Text; namespace ConsoleApplication4 { class Program { pu ...
- 配置samba的流程
1.关闭防火墙和selinuxservice iptables stopsetenforce 02.配置本地yummount /dev/cdrom /mediacd /etc/yum.repos.dc ...
- Configuring SSL for SAP Host Agent on UNIX
https://help.sap.com/viewer/141cbf7f183242b0ad0964a5195b24e7/114/en-US/8d12f7b9244b44219bd14d619d3a2 ...
- 基础Gan代码解析
initializer总结: #f.constant_initializer(value) 将变量初始化为给定的常量,初始化一切所提供的值. #tf.random_normal_initializer ...
- 手机APP测试之monkey
Monkey测试是一种为了测试软件稳定性.健壮性的快速有效的方法,Monkey程序由Android系统自带,使用Java语言写成.本此由于公司APP产品所需,用monkey进行稳定性测试,下面将本次使 ...
- Java学习随笔(1)--groovy爬虫
package com.fan import com.fission.source.httpclient.ApiLibraryimport com.fission.source.httpclient. ...
- Java数据类型(primitive)原始数据类型
1.小心别溢出来. 要确保变量能存下来所保存的值. 你无法用小杯子装大值.好吧,其实可以,但是会损失某些信息,也就是所说的溢位.当判断到所使用的容器不足以装载时,编译器会试着防止珍重情况发生.举例来说 ...
- jeecg-boot 简易部署方案
jeecg-boot采用前后端分离的方案,前后端代码不在一起.想要部署 一般是通过反向代理实现. jeecg-boot目前支持更好更简单的解决方案: jeecg 在配置文件里面指定了 webapp的存 ...