leetcode-625. Minimum Factorization
来源:互联网 发布:怎么查看网络是否稳定 编辑:程序博客网 时间:2024/06/01 09:25
考察点:简单的运算问题。
思路:从9到2遍历,思路简单,但需要注意的细节很多,首先应该用long long接受ret,如果是超出范围的的则return 0;然后a为1的情况下应该退出循环;循环外a不为1的情况下return 0;
C++代码:
class Solution {public: int num[10] = {2,3,4,5,6,7,8,9}; long long pow(long long a, int n) { long long ret = 1; for (int i=0; i<n; i++) ret *= a; return ret; } int smallestFactorization(int a) { if (a == 1) return 1; int time = 0; long long ret = 0; //int index = 7; for (int i=7; i>=0; i--) { while(a % num[i] == 0) { a /= num[i]; time++; ret += pow(10,time-1) * num[i]; if (ret > INT_MAX) return 0; cout<<num[i]<<" "<<a<<endl; } if (a == 1) break; } if (a == 1) return ret; else return 0; }};
阅读全文
0 0
- leetcode-625. Minimum Factorization
- leetcode 625. Minimum Factorization
- leetcode 625. Minimum Factorization
- LeetCode Minimum Factorization
- 625. Minimum Factorization
- Minimum Factorization
- 625. Minimum Factorization & 621. Task Scheduler
- 625Minimum Factorization
- Factorization
- LeetCode: Minimum Path Sum
- LeetCode: Minimum Window Substring
- LeetCode Minimum Path Sum
- LeetCode Minimum Window Substring
- LeetCode : Minimum Path Sum
- LeetCode : Minimum Window Substring
- [Leetcode] Minimum Path Sum
- [LeetCode] Minimum Path Sum
- [LeetCode] Minimum Window Substring
- h264编码原理以及I帧B帧P帧
- scikit-learn学习之SVM算法
- LDA-inference
- 【APICloud】Android数字证书概述
- 2- python 流程控制篇
- leetcode-625. Minimum Factorization
- AMD、CMD、webpack理解
- Android中View绘制过程(四) performMeasure
- http切换到https的tomcat配置
- Oracle中的闪回
- leetcode624: Maximum Distance in Arrays
- 3-python 函数篇
- javascript中的数值转换与逻辑非的比较
- jsp页面的前进刷新后退