Find the largest palindrome made from the product of two 3-digit numbers

前端 未结 17 988
天涯浪人
天涯浪人 2021-02-02 04:27
package testing.project;

public class PalindromeThreeDigits {

    public static void main(String[] args) {
        int value = 0;
        for(int i = 100;i <=999;i+         


        
17条回答
  •  北恋
    北恋 (楼主)
    2021-02-02 05:24

    Most probably it is replication of one of the other solution but it looks simple owing to pythonified code ,even it is a bit brute-force.

    def largest_palindrome():
        largest_palindrome = 0;
        for i in reversed(range(1,1000,1)):
            for j in reversed(range(1, i+1, 1)):
                num = i*j
                if check_palindrome(str(num)) and  num > largest_palindrome :
                    largest_palindrome = num 
        print "largest palindrome ", largest_palindrome
    
    def check_palindrome(term):
        rev_term = term[::-1]
        return rev_term == term
    

提交回复
热议问题