当前位置:网站首页>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
、3
and5
The positive integer . Give you an integern
, Please judgen
Is 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)
边栏推荐
- Ut2014 supplementary learning notes
- Boston house price forecast (tensorflow2.9 practice)
- [LZY learning notes dive into deep learning] 3.1-3.3 principle and implementation of linear regression
- 20220606数学:分数到小数
- Class-Variant Margin Normalized Softmax Loss for Deep Face Recognition
- I really want to be a girl. The first step of programming is to wear women's clothes
- Standard library header file
- ThreadLocal原理及使用场景
- Judging the connectivity of undirected graphs by the method of similar Union and set search
- Jetson TX2 刷机
猜你喜欢
六、MySQL之数据定义语言(一)
A super cool background permission management system
Hands on deep learning pytorch version exercise solution -- implementation of 3-2 linear regression from scratch
Deep Reinforcement learning with PyTorch
Class-Variant Margin Normalized Softmax Loss for Deep Face Recognition
ECMAScript -- "ES6 syntax specification # Day1
Boston house price forecast (tensorflow2.9 practice)
A complete mall system
Rewrite Boston house price forecast task (using paddlepaddlepaddle)
Data preprocessing - Data Mining 1
随机推荐
Handwritten digit recognition: CNN alexnet
Softmax 回归(PyTorch)
Yolov5 creates and trains its own data set to realize mask wearing detection
深度学习入门之自动求导(Pytorch)
Stroke prediction: Bayesian
Hands on deep learning pytorch version exercise solution -- implementation of 3-2 linear regression from scratch
2018 Lenovo y7000 black apple external display scheme
Hands on deep learning pytorch version exercise solution - 2.6 probability
重写波士顿房价预测任务(使用飞桨paddlepaddle)
Model evaluation and selection
Secure in mysql8.0 under Windows_ file_ Priv is null solution
CSDN, I'm coming!
Ind kwf first week
Ind yff first week
Policy Gradient Methods of Deep Reinforcement Learning (Part Two)
Introduction to deep learning linear algebra (pytorch)
The imitation of jd.com e-commerce project is coming
Linear regression of introduction to deep learning (pytorch)
熵值法求权重
Leetcode刷题---367