当前位置:网站首页>Leetcode -- number of palindromes
Leetcode -- number of palindromes
2022-07-02 16:01:00 【Nanchu】
Title Description
- 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
How to solve the problem
Method 1
var isPalindrome = function(x) { let s=x+""; let result=[]; for(let i=s.length-1;i>=0;i--){ result.push(s[i]); } if(s==result.join("")){ return true; } else{ return false; } };
Method 2
var isPalindrome = function(x) { return x.toString()==x.toString().split('').reverse().join(''); };
边栏推荐
- Add user-defined formula (time sharing t+0) to mobile app access as an example
- Experiment collection of University "Fundamentals of circuit analysis". Experiment 7 - Research on sinusoidal steady-state circuit
- Storage, reading and writing of blood relationship data of Nepal Graph & Data Warehouse
- Fiddler realizes mobile packet capturing - getting started
- 蚂蚁集团大规模图计算系统TuGraph通过国家级评测
- Group by的用法
- PyObject 转 char* (string)
- (万字精华知识总结)Shell脚本编程基础知识
- Jsp+mysql006 community management system
- Analysis of the difference between array and linked list
猜你喜欢
Review materials for the special topic of analog electronics with all essence: basic amplification circuit knowledge points
Experiment collection of University "Fundamentals of circuit analysis". Experiment 7 - Research on sinusoidal steady-state circuit
2020.4.12 byte written test questions B DP D monotone stack
Figure database | Nepal graph v3.1.0 performance report
全是精华的模电专题复习资料:基本放大电路知识点
Comparison between rstan Bayesian regression model and standard linear regression model of R language MCMC
Recommended practice sharing of Zhilian recruitment based on Nebula graph
idea 公共方法抽取快捷键
Experiment collection of University Course "Fundamentals of circuit analysis". Experiment 5 - Research on equivalent circuit of linear active two terminal network
Write your own CPU Chapter 11 - learning notes
随机推荐
Recommended practice sharing of Zhilian recruitment based on Nebula graph
idea 公共方法抽取快捷键
将点云坐标转换成世界坐标的demo
Lseek error
制作p12证书[通俗易懂]
Fiddler realizes mobile packet capturing - getting started
/Bin/ld: cannot find -lxml2
PHP static members
What are the necessary functions of short video app development?
AWS云主机扩容
In memory of becoming the first dayu200 tripartite demo contributor
[fluent] dart language (DART language features | JIT instant compilation | AOT static compilation)
Another graduation season
微信v3native支付设置的结束时间处理办法
Idea public method extraction shortcut key
Various entanglements between qvariant and Jason -- QT
全方位解读服务网格(Service Mesh)的背景和概念
SQL modification statement
手机app通达信添加自定义公式(分时T+0)为例子讲解
/Bin/ld: cannot find -lcrypto