当前位置:网站首页>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)
边栏推荐
- Step 1: teach you to trace the IP address of [phishing email]
- Secure in mysql8.0 under Windows_ file_ Priv is null solution
- Leetcode刷题---35
- What useful materials have I learned from when installing QT
- Julia1.0
- Knowledge map reasoning -- hybrid neural network and distributed representation reasoning
- Ut2016 learning notes
- OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow
- Softmax 回归(PyTorch)
- Timo background management system
猜你喜欢

Raspberry pie 4B installs yolov5 to achieve real-time target detection

Hands on deep learning pytorch version exercise solution - 2.4 calculus

【SQL】一篇带你掌握SQL数据库的查询与修改相关操作

An open source OA office automation system

Policy gradient Method of Deep Reinforcement learning (Part One)

Configure opencv in QT Creator

Deep Reinforcement learning with PyTorch

Label Semantic Aware Pre-training for Few-shot Text Classification

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

Leetcode - 705 design hash set (Design)
随机推荐
20220608其他:逆波兰表达式求值
Leetcode刷题---75
Label Semantic Aware Pre-training for Few-shot Text Classification
I really want to be a girl. The first step of programming is to wear women's clothes
Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported
【毕业季】图匮于丰,防俭于逸;治不忘乱,安不忘危。
Leetcode - 706 design hash mapping (Design)*
Seata分布式事务失效,不生效(事务不回滚)的常见场景
Hands on deep learning pytorch version exercise solution - 3.1 linear regression
Standard library header file
An open source OA office automation system
Configure opencv in QT Creator
High imitation bosom friend manke comic app
Convolutional neural network (CNN) learning notes (own understanding + own code) - deep learning
20220610 other: Task Scheduler
Ind FHL first week
Leetcode刷题---35
Leetcode刷题---10
Raspberry pie 4B installs yolov5 to achieve real-time target detection
Secure in mysql8.0 under Windows_ file_ Priv is null solution