当前位置:网站首页>Leetcode skimming ---263
Leetcode skimming ---263
2022-07-03 10:35:00 【Long time no see 0327】
subject : Ugly number That is, only the prime factor is included
2、3and5The positive integer . Give you an integern, Please judgenIs it Ugly number . If it is , returntrue; otherwise , returnfalse.
Input :n = 6
Output :true
Method 1 : mathematics
class Solution {
public:
bool isUgly(int n) {
if (n <=0 ) {
return false;
}
vector<int> factors = {2, 3, 5};
for (int factor: factors) {
while (n % factor == 0) {
n /= factor;
}
}
return n == 1;
}
};Complexity analysis
Time complexity :O(logn)
Spatial complexity :O(1)
边栏推荐
- Leetcode刷题---704
- Standard library header file
- [C question set] of Ⅵ
- Several problems encountered in installing MySQL under MAC system
- SQL Server Management Studio cannot be opened
- 丢弃法Dropout(Pytorch)
- The imitation of jd.com e-commerce project is coming
- Convolutional neural network (CNN) learning notes (own understanding + own code) - deep learning
- Hands on deep learning pytorch version exercise solution - 3.1 linear regression
- Rewrite Boston house price forecast task (using paddlepaddlepaddle)
猜你喜欢

Advantageous distinctive domain adaptation reading notes (detailed)

Yolov5 creates and trains its own data set to realize mask wearing detection

七、MySQL之数据定义语言(二)

Ind wks first week

Multi-Task Feature Learning for Knowledge Graph Enhanced Recommendation

Ut2016 learning notes

ThreadLocal原理及使用场景

A super cool background permission management system

Anaconda installation package reported an error packagesnotfounderror: the following packages are not available from current channels:

LeetCode - 715. Range module (TreeSet)*****
随机推荐
Raspberry pie 4B installs yolov5 to achieve real-time target detection
20220608 other: evaluation of inverse Polish expression
Judging the connectivity of undirected graphs by the method of similar Union and set search
七、MySQL之数据定义语言(二)
Multi-Task Feature Learning for Knowledge Graph Enhanced Recommendation
Convolutional neural network (CNN) learning notes (own understanding + own code) - deep learning
Inverse code of string (Jilin University postgraduate entrance examination question)
Hands on deep learning pytorch version exercise solution - 2.6 probability
波士顿房价预测(TensorFlow2.9实践)
Ut2012 learning notes
EFFICIENT PROBABILISTIC LOGIC REASONING WITH GRAPH NEURAL NETWORKS
LeetCode - 715. Range module (TreeSet)*****
【毕业季】图匮于丰,防俭于逸;治不忘乱,安不忘危。
Data preprocessing - Data Mining 1
Leetcode-404:左叶子之和
[graduation season] the picture is rich, and frugality is easy; Never forget chaos and danger in peace.
Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported
Leetcode-404: sum of left leaves
What did I read in order to understand the to do list
3.3 Monte Carlo Methods: case study: Blackjack of Policy Improvement of on- & off-policy Evaluation