Problem 4 Largest palindrome product
来源:互联网 发布:敷面膜知乎 编辑:程序博客网 时间:2024/06/06 01:52
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.
第一版:判断数字回文直接反转数字
def reverse(number):r = 0while number >0:last_digit = number % 10r = r * 10 + last_digitnumber = number / 10return rdef is_palindrome(number):return reverse(number) == numberdef run():largest = 0for i in range(100,1000):for j in range(100,1000):product = i * jif is_palindrome(product) and product>largest:largest = productreturn largest
第二版:将数字转为字符串:通过 str[::-1] 反转字符串
def run2():largest = 0for i in range(100,1000):for j in range(100,1000):product = i * jstrProduct = str(product)if strProduct == strProduct[::-1] and product > largest:largest = productreturn largest
第三版:一行python
def run3():return max([x*y for x in range(100,1000) for y in range(100,1000) if str(x*y) == str(x*y)[::-1]])
阅读全文
0 0
- Problem 4:Largest palindrome product
- Problem 4:Largest palindrome product
- Problem 4 Largest palindrome product
- 【Project Euler】【Problem 4】Largest palindrome product
- (Problem 4)Largest palindrome product
- projecteuler---->problem=4----Largest palindrome product
- Project Euler Problem 4: Largest palindrome product
- Proiect Euler problem 4 : Largest palindrome product
- Problem 4 Largest palindrome product (暴力枚举)
- PE 4 Largest palindrome product
- 【欧拉计划4】Largest palindrome product
- 4 Largest palindrome product - Project Eulder
- projecteuler.net 4--Largest palindrome product
- Largest palindrome product
- Largest palindrome product
- leetcode[Largest Palindrome Product]
- 479. Largest Palindrome Product
- 479. Largest Palindrome Product
- android studio 中要在app名称中添加&特殊符号
- Add Binary
- 深浅拷贝
- ios 拨打电话
- Activity深度剖析
- Problem 4 Largest palindrome product
- 计划任务里执行包含连接oracle命令的shell脚本报错:SP2-0667: Message file sp1<lang>.msb not found
- window下彻底卸载删除SQL Serever 2012
- (57)String类操作:获取、判断、转换
- 反序输出
- 【知识】贪心
- 用shell脚本实现监控程序自动重启
- 关于 SSH 工具里文件的颜色
- 各类算法实现(sort)