当前位置:网站首页>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)
边栏推荐
- High imitation bosom friend manke comic app
- Pytorch ADDA code learning notes
- Leetcode刷题---374
- A complete mall system
- [LZY learning notes dive into deep learning] 3.4 3.6 3.7 softmax principle and Implementation
- 丢弃法Dropout(Pytorch)
- LeetCode - 715. Range module (TreeSet)*****
- Ut2015 learning notes
- 六、MySQL之数据定义语言(一)
- What useful materials have I learned from when installing QT
猜你喜欢

Introduction to deep learning linear algebra (pytorch)

C#项目-寝室管理系统(1)

Stroke prediction: Bayesian

Hands on deep learning pytorch version exercise solution -- implementation of 3-2 linear regression from scratch

Multi-Task Feature Learning for Knowledge Graph Enhanced Recommendation

Jetson TX2 刷机

深度学习入门之线性代数(PyTorch)

Class-Variant Margin Normalized Softmax Loss for Deep Face Recognition

Leetcode-112: path sum

Label Semantic Aware Pre-training for Few-shot Text Classification
随机推荐
Leetcode刷题---1
实战篇:Oracle 数据库标准版(SE)转换为企业版(EE)
3.3 Monte Carlo Methods: case study: Blackjack of Policy Improvement of on- & off-policy Evaluation
Out of the box high color background system
Leetcode刷题---278
ThreadLocal原理及使用场景
Leetcode刷题---10
Standard library header file
Leetcode刷题---367
High imitation Netease cloud music
Tensorflow—Neural Style Transfer
Implementation of "quick start electronic" window dragging
Julia1.0
What useful materials have I learned from when installing QT
Leetcode - 706 design hash mapping (Design)*
Timo background management system
神经网络入门之矩阵计算(Pytorch)
20220602 Mathematics: Excel table column serial number
QT creator uses OpenCV Pro add
Pytorch ADDA code learning notes