当前位置:网站首页>JS judge palindromes
JS judge palindromes
2022-06-12 18:02:00 【Out of the autistic bird】
Judge the palindrome number
Form of array inversion
/** * Form of array inversion */
function findNums1(num){
const res = []
for(let i=1;i<=num;i++){
const s = i.toString()
if(s===s.split('').reverse().join('')){
res.push(i)
}
}
return res
}
Compare the beginning and end of the string
/** * Compare the beginning and end of the string */
function findNums2(num){
const res = []
for(let i=1;i<=num;i++){
const s = i.toString()
const length = s.length
// Compare the beginning and end of the string
let flag = true
let start = 0 // String start
let end = length-1 // End of string
while(start < end){
if(s[start] !== s[end]){
flag = false
break
}else {
// Continue to compare
start++
end--
}
}
if(flag) res.push(i)
}
return res
}
Pure digital comparison
/** * Pure digital comparison */
function findNums3(num){
const res = []
for(let i=1;i<=num;i++){
let n = i
let rev = 0 // Store the reverse rotation number
// Generate inversion number
while(n>0){
rev = rev*10+n%10
n = Math.floor(n/10)
}
if(i===rev) res.push(i)
}
return res
}
The performance is getting better and better from top to bottom
边栏推荐
- Introduction to reinforcement learning and analysis of classic items 1.3
- Eve-ng installation (network device simulator)
- When openharmony meets openeuler
- A story on the cloud of the Centennial Olympic Games belonging to Alibaba cloud video cloud
- Stream流注意点
- Article name
- 用grep awk提取字符串
- Is it safe to open an account in flush
- JDBC快速入门教程
- JS for Fibonacci sequence
猜你喜欢

Variable of C #

High-Speed Layout Guidelines 未完...

极限编程--根源分析实践

vant3 +ts 封装简易step进步器组件

High speed layout guidelines incomplete

有源差分晶振原理图以及LV-PECL、LVDS、HCSL区别

Make good use of IDE, speed up R & D efficiency by 100%

js两数之和

C#简单介绍

Click the list page of vant3+ts+pinia tab to enter the details. The tab on the details page is highlighted in the original position, and the refresh highlight is in the first item by default
随机推荐
Vant3 +ts packaged simple step advancer component
ESP32-C3 ESP-IDF 配置smartconfig 和 sntp 获取网络时间
Variable of C #
Use the official go Library of mongodb to operate the original mongodb
Continued 2 asp Net core router basic use demonstration 0.2 acquisition of default controller data
String s = null ; String s = new String(); String s = "; what is the difference between string s?
"Big fat • small lesson" - talk about big file segmentation and breakpoint sequel
Codeforces Round #398 (Div. 2) D. Cartons of milk
leetcode151 翻转字符串里的单词
Detailed description of SQL cursor and example of internal recycling
PHP implementation of infinite classification tree (recursion and Optimization)
JDBC several pits
用grep awk提取字符串
TypeScript常用类型(一)
Stream flow precautions
Goframe gredis configuration management | comparison of configuration files and configuration methods
Still using Microsoft office, 3 fairy software, are you sure you don't want to try?
Applet and app are owned at the same time? A technical scheme with both
channel原创
EasyCode模板