[Leetcode] 625. Minimum Factorization 解题报告
题目:
Given a positive integer a
, find the smallest positive integer b
whose multiplication of each digit equals to a
.
If there is no answer or the answer is not fit in 32-bit signed integer, then return 0.
Example 1
Input:
48
Output:
68
Example 2
Input:
15
Output:
35
思路:
可以观察到两个事实:1)n位数一定小于n+1位的数;2)如果几个结果都是n位数,那么将各个位上的数按照升序排列,则形成的n位数结果是最小的。所以我们的思路就是尽量让结果的位数小,并且让因数从大到小。所以可以让i从9循环到2,按照顺序找出a中所有9-2之间的因数(注意不是质因数),然后将它们按照升序排列,形成的结果即为题目所求。我们这里让d < 10是为了防止int溢出。
代码:
class Solution {
public:int smallestFactorization(int a) {if (a < 2) {return a;}long l = 0;for (int i = 9, d = 0; i >= 2 && d < 10; --i) {while (a % i == 0 && d < 10) {l += i * pow(10, d++);a /= i;}}return a > 1 || l > INT_MAX ? 0 : l;}
};
[Leetcode] 625. Minimum Factorization 解题报告相关推荐
- 【LeetCode】3Sum Closest 解题报告
[题目] Given an array S of n integers, find three integers in S such that the sum is closest to a give ...
- LeetCode Maximum Product Subarray 解题报告
LeetCode 新题又更新了.求:最大子数组乘积. https://oj.leetcode.com/problems/maximum-product-subarray/ 题目分析:求一个数组,连续子 ...
- 【LeetCode】77. Combinations 解题报告(Python C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:递归 方法二:回溯法 日期 题目地址:htt ...
- [LeetCode] Sqrt(int x)解题报告之无限逼近(牛顿法)
Implement int sqrt(int x). Compute and return the square root of x. 求一个数的平方根.这道题的难点在于虽然接口的参数给的是int,但 ...
- [leetcode] 28. Implement strStr() 解题报告
题目链接:https://leetcode.com/problems/implement-strstr/ Implement strStr(). Returns the index of the fi ...
- LeetCode 488 Zuma Game 解题报告
原文链接: http://hankerzheng.com/blog/Leetcode-Zuma-Game- Problem Description LeetCode 488 Zuma Game Thi ...
- 【LeetCode】Palindrome Partitioning 解题报告
[题目] Given a string s, partition s such that every substring of the partition is a palindrome. Retur ...
- LeetCode 705 Design HashSet 解题报告
题目要求 Design a HashSet without using any built-in hash table libraries. To be specific, your design s ...
- LeetCode: First Missing Positive 解题报告
Q: Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2 ...
最新文章
- 梯度下降到底是什么?
- bootstrap项目实例_精选开源SpringBoot项目:涵盖权限、搜索、秒杀、支付!
- Mr.J-- jQuery学习笔记(二十七)--DOM操作方法(删除获取文本)
- 陌陌直播公益课复课 带乡村孩子“打卡”丝绸之路
- 详细叙述ajax的详情,ajax的配置详情、ajax的调用解释、ajax的中文乱码和ajax的表单提交(内有实例)...
- java打开的文件过多_显示打开文件数目过多的解决方法.
- LaTeX Cookbook by Eric
- 第4章 旋转蛇(《C和C++游戏趣味编程》配套教学视频)
- 经典排序算法(二十)--Strand Sort
- MATLAB随机信号分析与处理
- java 读取 解析微软Project .mpp 文件
- 远程登陆没有固定ip的服务器
- 答:本科生写论文对考研有用吗?
- 基于PaddleGAN项目人脸表情动作迁移学习(五)图像补帧上色与超分修复
- 通信电子:RLC电路及滤波器
- 查看python的版本号有 四种方案
- 计算机网络怎么运行内存,电脑运行内存怎么扩大(教你使用虚拟内存来增加win7系统的运行内存)...
- 信息安全系列(3)--从王宝*离婚案论个人信息安全
- 我国网络安全现状怎么样?如何应对网络安全风险?
- UCI Susy Data set
热门文章
- Android 内部存储和外部存储
- 不忘初心,能偷懒就偷懒:C#操作Word文件
- 仿照余额宝余额动态变动
- php仿淘宝课程设计任务书
- 七十七、java版商城之直播短视频带货Spring Cloud+SpringBoot+mybatis+uniapp b2b2c o2o 多商家入驻商城 直播带货商城 电子商务
- Linux 文字雨特效
- VC实现EXCEL转换为CSV格式
- iPad 必备软件 | 帮你实现百度云倍速
- 抽象类和抽象方法_30酷抽象和背景Photoshop教程
- php用户登录界面代码有背景,大男孩教你怎么自定义WordPress用户登录界面背景图片? – 男孩资源网...