-
-
Notifications
You must be signed in to change notification settings - Fork 229
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~10000 以内的对称数 #137
Comments
function isSymmetryNum(start,end){
for(let i = start; i < end + 1; i++){
let str = String(i);
if(str.length <= 1) continue;
if(str.split("").reverse().join("") === str){
console.log(i);
}
}
}
isSymmetryNum(1,10000) |
function getDuicheng() {
const res = [];
for (let i = 1; i < 10; i++) {
res.push(i);
res.push(i * 11);
for (let j = 0; j < 10; j++) {
res.push(i * 101 + j * 10); //101-999
res.push(i * 1001 + j * 110); //1001-9999
}
}
return res;
} |
const res = [];
function getSymNum() {
for (let i = 1; i <= 10000; i++) {
let str1 = i + "";
if (judgeSym(str1)) res.push(i);
}
}
function judgeSym(str) {
let l = 0,
r = str.length - 1;
while (l < r) {
if (str[l] !== str[r]) return false;
r--;
l++;
}
return true;
}
getSymNum();
console.log(res); 简单的双指针 |
const isSymmetryNum = (start, end) => { for (let i = start; i < end; i++) { return res |
function symmetric(num) {
const result = [];
const nums = Array.from({ length: num }, (_, i) => 1 + i);
while (nums.length > 0) {
const lastNum = nums.pop();
if (String(lastNum).split("").reverse().join("") === String(lastNum)) {
result.push(lastNum);
}
}
return result;
} |
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: