当前位置:网站首页>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
边栏推荐
- leetcode 647. 回文子串
- This shift, I still have to go
- 1.5 what is an architect (serialization)
- Explanation of core interrupt of Godson processor
- 机器学习系列(5):朴素贝叶斯
- Applet and app are owned at the same time? A technical scheme with both
- js将数组中的0移动到末尾
- Random talk about redis source code 90
- Use applet to quickly generate app in seven steps
- DRM driven MMAP detailed explanation: (I) preliminary knowledge
猜你喜欢

Nixos 22.05 installation process record

Vant3+ts H5 pages are nested into apps to communicate with native apps

Lightweight and convenient small program to app technology solution to realize interconnection with wechat / traffic app

企业架构的第一性原理

es7不使用父子和嵌套关系来实现一对多功能

High-Speed Layout Guidelines 未完...

First principles of enterprise architecture

Vant3+ts dropdownmenu drop-down menu, multi data can be scrolled

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

vant3+ts+pinia tab选项卡列表页面点击进详情,详情页返回tab高亮在原位置,刷新高亮默认在第一项
随机推荐
用grep awk提取字符串
String s = null ; String s = new String(); String s = "; what is the difference between string s?
USB to serial port - maximum peak serial port baud rate vs maximum continuous communication baud rate
js两数之和
Introduction to reinforcement learning and analysis of classic items 1.3
TypeScript常用类型(一)
Vulnhub[DC3]
极限编程--根源分析实践
使用MongoDB官方go库操作MongoDB原创
Authorization in Golang ProjectUseing Casbin
Project training of Software College of Shandong University - Innovation Training - network attack and defense shooting range experimental platform of Software College of Shandong University (XXV) - p
leetcode 300. Longest increasing subsequence
es7不使用父子和嵌套关系来实现一对多功能
机器学习系列(5):朴素贝叶斯
低代码平台调研结果
Getting started with grpc swift
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
AlibabaProtect. How to delete and uninstall exe
Vulnhub[DC3]
A method of quickly reusing wechat login authorization in app