- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我得到的答案不是正确的(正确答案是 906609)。请帮助我理解我哪里出了问题。我希望 while 循环从 100 到 999,同时在循环递增之前将其自身与当前 i
值相乘。
// A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
// Find the largest palindrome made from the product of two 3-digit numbers.
var pali = [];
function palindrome() {
for (var i = 100; i <= 999; i++) {
var counter = 100;
while (counter <= 999) {
var result = counter * i;
if (result.toString() === result.toString().split("").reverse().join("")) {
pali.push(result);
}
counter++;
}
}
return pali[pali.length - 1];
}
console.log(palindrome());
最佳答案
如果您希望最后一个成为最高的,则必须按升序对数组进行排序:
pali.sort(function(a, b){return a-b});
使用它,我得到 906609。
关于javascript - 我对两个三位数乘积的最大回文数的解决方案需要工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39776410/
我正在编写 Java 代码,我必须在其中创建一个返回带有一个参数的 boolean 值的方法。如果提供给它的数字(参数)是否为回文,代码必须识别真假。这是我的代码,但结果始终是错误的。有人可以确定这里
我必须判断一个整数是否是JAVA中的回文数。我需要帮助理解为什么我编写的代码返回 Time Limit Exceeded? class Solution { public boolean is
这是工作代码: p = (10..14).map { |a| (a..14).map { |b| a * b } flatten.select { |p| p.to_s == p.
可计算任意位水仙花数 复制代码代码如下: public static void main(String[] args) { int max
1.题目描述: 难度:简单 描述: 给你一个整数 x ,如果 x 是一个回文整数,返回 true ;否则,返回 false 。 回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。 例如,1
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 已关闭 7 年前。 Improve
谁能帮我这个c程序。我正在尝试执行这个回文检查代码,但在我输入数字后它没有被执行。有什么错误吗? #include int main() { int num,rev=0,r,temp;
本文关键词:回文数,回文,题解,Leetcode, 力扣,Python, C++, Java 题目地址:https://leetcode.com/problems/palindrome-number
9. 回文数 题目描述 解题思路 首先将整数x转换为字符串型x_str; 遍历x_str.length()/2次,比较第 i 位与倒数第 i 位字符是否相同,如果不同返回false; 遍历结束,返回t
我是一名优秀的程序员,十分优秀!