Skip to content
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

Open
Sunny-117 opened this issue Nov 3, 2022 · 4 comments
Open

1-1000回文数 #127

Sunny-117 opened this issue Nov 3, 2022 · 4 comments

Comments

@Sunny-117
Copy link
Owner

No description provided.

@mengqiuleo
Copy link

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))

@bearki99
Copy link

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);

@HangHZhang
Copy link

HangHZhang commented Feb 22, 2023

function palindromes1(num) {
    return +((''+num).split('').reverse().join('')) === num
}

@HangHZhang
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants