-
-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1-1000回文数 #127
Comments
function getReverseNumber(num){
const res = [];
for(let i=10; i<=num; i++){
let a = i.toString();
let b = a.split('').reverse().join('');
if(a == b){
res.push(b);
}
}
return res;
}
console.log(getReverseNumber(1000)) |
function isReverse(num) {
let newNum = num + "";
let l = 0,
r = newNum.length - 1;
while (l < r) {
if (newNum[l] !== newNum[r]) return false;
l++;
r--;
}
return true;
}
const res = [];
for (let i = 1; i <= 1000; i++) {
if (isReverse(i)) res.push(i);
}
console.log(res); |
function palindromes1(num) {
return +((''+num).split('').reverse().join('')) === num
} |
function palindromes2(num) {
const numStr = '' + num
let left = 0;
let right = numStr.length - 1
while ( left <= right) {
if (numStr[left++] === numStr[right--]) {
continue
} else {
return false
}
}
return true
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: