479. Largest Palindrome Product
来源:互联网 发布:淘宝网书城首页 编辑:程序博客网 时间:2024/05/21 14:44
题目:
Find the largest palindrome made from the product of two n-digit numbers.
Since the result could be very large, you should return the largest palindrome mod 1337.
Example:
Input: 2
Output: 987
Explanation: 99 x 91 = 9009, 9009 % 1337 = 987
Note:
The range of n is [1,8].
思路:本题属于简单题,求最大回文,直接的思路是构造回文并比较,但是感觉这样做不简单,于是思考,回文特征,发现两数成绩构造的最大回文是有限个数:9, 9009, 906609, 99000099, 9966006699, 999000000999,99956644665999, 9999000000009999,所以本题使用枚举法:
代码:
class Solution {public: int largestPalindrome(int n) { vector<long> res = {9, 9009, 906609, 99000099, 9966006699, 999000000999, \ 99956644665999, 9999000000009999}; return int(res[n - 1] % 1337); }};
阅读全文
0 0
- 479. Largest Palindrome Product
- 479. Largest Palindrome Product
- 479. Largest Palindrome Product
- 479. Largest Palindrome Product
- leetcode 479. Largest Palindrome Product
- {LeetCode} 479. Largest Palindrome Product
- LeetCode: 479. Largest Palindrome Product
- leetcode 479. Largest Palindrome Product
- [Leetcode] 479. Largest Palindrome Product 解题报告
- Largest palindrome product
- Largest palindrome product
- leetcode[Largest Palindrome Product]
- Problem 4:Largest palindrome product
- Problem 4:Largest palindrome product
- PE 4 Largest palindrome product
- Problem 4 Largest palindrome product
- 【leetcode】479. Largest Palindrome Product(Python & C++)
- leetcode 479. Largest Palindrome Product最大的回文乘积
- 【IDE】IntelliJ IDEA (Mac) 运行速度优化(问题起因:debug模式突然变得巨慢)
- 学生信息管理系统的构建3--库文件的调用【待续】
- 智能小车十四《小车如何控制电视》
- MyBatis -- 事务管理机制 JDBC
- Unity灯光效果及设置详解
- 479. Largest Palindrome Product
- Vivado下几条 Verilog 综合规则
- 安装oracle11g碰到的各种问题
- 51nod 1062 序列中最大的数
- 数字1的数量
- idea使用maven配置mybatis环境以及idea中集成log4j
- boost学习笔记之assign
- 最近做文件上传,使用了jQuery-uploadify插件,用的是官网最新的3.2版本,官网地址:http://www.uploadify.com/download/ 在这里建议下:在面对最新的版
- 【juincen】Web中图片上传处理 jQuery+Ajax+SpringMVC