进阶之路

导航

Problem 4: Largest palindrome product

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.

3位数的话,就从999开始,为了减少遍历次数,就先从999-900,如果没有条件满足,再放大这个范围

l = []
for i in range(999, 900, -1):
    for j in range(999, 900, -1):
            n = str(i * j)
            if n == n[::-1]:
                l.append(int(n))
print(max(l))

执行结果:906609

posted on 2017-11-28 11:42  中年小Q  阅读(166)  评论(0编辑  收藏  举报