当前位置:网站首页>Leetcode003 -- judge whether an integer is a palindrome number
Leetcode003 -- judge whether an integer is a palindrome number
2022-04-23 04:39:00 【singularityDZF】
import java.util.Scanner;
/**
* Give you an integer x , If x Is a palindrome integer , return true ; otherwise , return false .
* Palindrome number refers to positive order ( From left to right ) Reverse order ( From right to left ) Read all the same integers . for example ,121 It's palindrome. , and 123 No .
*
* Example 1:
* Input :x = 121
* Output :true
*
* Example 2:
* Input :x = -121
* Output :false
* explain : Read left to right , by -121 . Read right to left , by 121- . So it's not a palindrome number .
*
* Example 3:
* Input :x = 10
* Output :false
* explain : Read right to left , by 01 . So it's not a palindrome number .
*
* Example 4:
* Input :x = -101
* Output :false
*
*
* Tips :
* -231<= x <= 231- 1
*
*/
public class test03 {
public static void main(String[] args) {
System.out.print(" Please enter a number :");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
if(isPalindrome(num)){
System.out.println(num+" It's palindrome number !");
}else{
System.out.println(num+" Not palindrome !");
}
}
public static boolean isPalindrome(int x){
if(x < 0 || x%10==0 && x!=0){
return false;
}
else {
int reverNumber = 0;
while (x > reverNumber) {
reverNumber = reverNumber * 10 + x % 10;
x /= 10;
}
return x == reverNumber || x == reverNumber/10;
}
}
}
版权声明
本文为[singularityDZF]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230438035490.html
边栏推荐
- VHDL implementation of 32-bit binary to BCD code
- test
- MYSQL去重方法汇总
- Chapter 4 - understanding standard equipment documents, filters and pipelines
- 补充番外14:cmake实践项目笔记(未完待续4/22)
- 上海航芯技术分享 | ACM32 MCU安全特性概述
- Inverse system of RC low pass filter
- Improving 3D object detection with channel wise transformer
- [timing] empirical evaluation of general convolution and cyclic networks for sequence modeling based on TCN
- win10, mysql-8.0.26-winx64.zip 安装
猜你喜欢
针对NFT的网络钓鱼
做数据可视化应该避免的8个误区
[paper reading] [3D object detection] voxel transformer for 3D object detection
Detailed explanation of life cycle component of jetpack
Record your own dataset with d435i, run orbslam2 and build a dense point cloud
[AI vision · quick review of NLP natural language processing papers today, No. 32] wed, 20 APR 2022
How to regulate intestinal flora? Introduction to common natural substances, probiotics and prebiotics
用D435i录制自己的数据集运行ORBslam2并构建稠密点云
Matlab minimalist configuration of vscode configuration
Effects of antibiotics on microbiome and human health
随机推荐
/etc/bash_completion.d目录作用(用户登录立刻执行该目录下脚本)
[AI vision · quick review of today's sound acoustic papers, issue 3] wed, 20 APR 2022
The perfect combination of collaborative process and multi process
thymeleaf th:value 为null时报错问题
AWS eks add cluster user or Iam role
zynq平臺交叉編譯器的安裝
【Pytorch基础】torch.split()用法
Installation of zynq platform cross compiler
【时序】基于 TCN 的用于序列建模的通用卷积和循环网络的经验评估
递归调用--排列的穷举
三十六计是什么
Stm32f4 MCU ADC sampling and FFT of ARM-DSP Library
记录一下盲注脚本
KVM error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock‘
Interaction of diet gut microbiota on cardiovascular disease
Go reflection rule
【论文阅读】【3d目标检测】point transformer
C语言: 指针的进阶
leetcode002--将有符号整数的数字部分反转
Go 语言中的 logger 和 zap 日志库