当前位置:网站首页>【Leetcode】479. Largest Palindrome Product
【Leetcode】479. Largest Palindrome Product
2022-08-01 23:47:00 【记录算法题解】
题目地址:
https://leetcode.com/problems/largest-palindrome-product/
给定一个正整数 1 ≤ n ≤ 8 1\le n\le 8 1≤n≤8,求最大的回文数 x x x使得 x x x能分解为两个 n n n位数的乘积。
直接暴力枚举即可。代码如下:
class Solution {
public:
int largestPalindrome(int n) {
if (n == 1) return 9;
int maxv = pow(10, n) - 1;
for (int i = maxv;; i--) {
auto a = to_string(i);
auto b = a;
reverse(b.begin(), b.end());
auto num = stoll(a + b);
for (long j = maxv; j * j >= num; j--)
if (num % j == 0) return num % 1337;
}
return 0;
}
};
时间复杂度 O ( 1 0 n ) O(10^n) O(10n),空间 O ( n ) O(n) O(n)。
边栏推荐
- 带你搞懂MySQL隔离级别,两个事务同时操作同一行数据会怎样?
- The monthly salary of the test post is 5-9k, how to increase the salary to 25k?
- IDEA common plugins
- Is TCP reliable?Why?
- 多御安全浏览器android版更新至1.7,改进加密协议
- With a monthly salary of 12K, the butterfly changed to a new one and moved forward bravely - she doubled her monthly salary through the career change test~
- Work for 5 years, test case design is bad?To look at the big case design summary
- 使用Jenkins做持续集成,这个知识点必须要掌握
- 程序员还差对象?new一个就行了
- qt-faststart installation and use
猜你喜欢

GIF制作-灰常简单的一键动图工具

Flink Yarn Per Job - CliFrontend

The third chapter of the imitation cattle network project: develop the core functions of the community (detailed steps and ideas)

【MySQL篇】初识数据库

经典文献阅读之--DLO

12306抢票,极限并发带来的思考?

2022还想上岸学习软件测试必看,测试老鸟的肺腑之言...

Building a cloud-native DevOps environment

async和await用法介绍

CDH6 Hue to open a "ASCII" codec can 't encode characters
随机推荐
检查 Oracle 版本的 7 种方法
Chrome书签插件,让你实现高效整理
Thesis understanding [RL - Exp Replay] - Experience Replay with Likelihood-free Importance Weights
async和await用法介绍
6133. 分组的最大数量
【MySQL篇】初识数据库
Avoid , ,
, and tagsSql之各种Join
带你搞懂MySQL隔离级别,两个事务同时操作同一行数据会怎样?
cdh6 opens oozieWeb page, Oozie web console is disabled.
Appears in oozie on CDH's hue, error submitting Coordinator My Schedule
Solve the port to take up
How to better understand and do a good job?
Several interview questions about golang concurrency
Is TCP reliable?Why?
@WebServlet注解(Servlet注解)
【MySQL系列】 MySQL表的增删改查(进阶)
Thinkphp 5.0.24变量覆盖漏洞导致RCE分析
在linux下MySQL的常用操作命令
在MySQL中使用MD5加密【入门体验】