479 Largest Palindrome Product 最大回文数乘积
你需要找到由两个 n 位数的乘积组成的最大回文数。
由于结果会很大,你只需返回最大回文数 mod 1337得到的结果。
示例:
输入: 2
输出: 987
解释: 99 x 91 = 9009, 9009 % 1337 = 987
说明:
n 的取值范围为 [1,8]。
详见:https://leetcode.com/problems/largest-palindrome-product/description/
C++:
class Solution {
public:
int largestPalindrome(int n)
{
int upper = pow(10, n) - 1, lower = upper / 10;
for (int i = upper; i > lower; --i)
{
string t = to_string(i);
long p = stol(t + string(t.rbegin(), t.rend()));
for (long j = upper; j * j > p; --j)
{
if (p % j == 0)
{
return p % 1337;
}
}
}
return 9;
}
};
参考:http://www.cnblogs.com/grandyang/p/7644725.html
479 Largest Palindrome Product 最大回文数乘积的更多相关文章
- [LeetCode] Largest Palindrome Product 最大回文串乘积
Find the largest palindrome made from the product of two n-digit numbers. Since the result could be ...
- Java实现 LeetCode 479 最大回文数乘积
479. 最大回文数乘积 你需要找到由两个 n 位数的乘积组成的最大回文数. 由于结果会很大,你只需返回最大回文数 mod 1337得到的结果. 示例: 输入: 2 输出: 987 解释: 99 x ...
- Leetcode 479.最大回文数乘积
最大回文数乘积 你需要找到由两个 n 位数的乘积组成的最大回文数. 由于结果会很大,你只需返回最大回文数 mod 1337得到的结果. 示例: 输入: 2 输出: 987 解释: 99 x 91 = ...
- [Swift]LeetCode479. 最大回文数乘积 | Largest Palindrome Product
Find the largest palindrome made from the product of two n-digit numbers. Since the result could be ...
- 【easy】479. Largest Palindrome Product
Find the largest palindrome made from the product of two n-digit numbers Since the result could be v ...
- palindrome number(回文数)
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...
- [Leetcode] Palindrome number 判断回文数
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...
- 【LeetCode】9、Palindrome Number(回文数)
题目等级:Easy 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it rea ...
- 9. Palindrome Number[E]回文数
题目 Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same b ...
随机推荐
- A toolbox to build your own build server
A toolbox to build your own build server LambdaCD - Build Pipelines as Code https://www.lambda.cd/ A ...
- 在C语言中使用libiconv进行编码转换的示例
libiconv_sample.c #include <stdio.h> #include <malloc.h> #include "libiconv/iconv.h ...
- Cats transport(codeforces311B)(斜率优化)
\(Cats Transport\) 感觉这道题题面不好讲,就自翻了一个新的,希望有助于大家理解其思路: 大致题意: \(wch\) 的家里有 \(N\) 座山(山呈直线分布,第 \(i-1\) 座山 ...
- scrollView 代理方法的实现顺序的些许区别
- yum下载对应内核版本的kernel-devel
1 查看内核版本 uname -r 2 查看目前已有的kernel-devel uname -a ; rpm -qa kernel\* | sort 3 下载对应版本 $ sudo yum insta ...
- DataSnap的如果网络断线,如何恢复?
timer代码很简单:var adbsevertime :TDateTime;begin try adbsevertime := ClientModule1.ServerMethods1Client. ...
- linux驱动开发之九鼎板载蜂鸣器驱动测试【转】
本文转载自:http://whylinux.blog.51cto.com/10900429/1932491 字符设备驱动用的fileopretion结构体. 1.板载蜂鸣器的驱动测试 我手里有一个BS ...
- HDU1520 Anniversary party —— 树形DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520 Anniversary party Time Limit: 2000/1000 MS (Java ...
- Silverlight DataBinding Converter:根据binding对象调整显示
Silverlight DataBinding Converter:根据binding对象调整显示 我希望写一系列关于Silverlight DataBinding的文章,分别讲解Silverligh ...
- Android 获取View宽度
/***************************************************************************** * Android 获取View宽度 * ...