当前位置:网站首页>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)
边栏推荐
- 20220608 other: evaluation of inverse Polish expression
- MySQL报错“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre”解决方法
- A complete answer sheet recognition system
- 20220610 other: Task Scheduler
- 20220605 Mathematics: divide two numbers
- An open source OA office automation system
- ECMAScript -- "ES6 syntax specification # Day1
- Hands on deep learning pytorch version exercise solution - 2.5 automatic differentiation
- [LZY learning notes dive into deep learning] 3.4 3.6 3.7 softmax principle and Implementation
- Ut2016 learning notes
猜你喜欢

Configure opencv in QT Creator

A complete mall system

Ut2015 learning notes

Powshell's set location: unable to find a solution to the problem of accepting actual parameters

Linear regression of introduction to deep learning (pytorch)

mysql5.7安装和配置教程(图文超详细版)

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

Flutter 退出当前操作二次确认怎么做才更优雅?

Handwritten digit recognition: CNN alexnet

Hands on deep learning pytorch version exercise solution - 2.4 calculus
随机推荐
Handwritten digit recognition: CNN alexnet
Julia1.0
20220606数学:分数到小数
20220609 other: most elements
Notes - regular expressions
What can I do to exit the current operation and confirm it twice?
【SQL】一篇带你掌握SQL数据库的查询与修改相关操作
CSDN, I'm coming!
Leetcode刷题---217
20220531 Mathematics: Happy numbers
Policy gradient Method of Deep Reinforcement learning (Part One)
六、MySQL之数据定义语言(一)
2018 Lenovo y7000 black apple external display scheme
Leetcode刷题---852
熵值法求权重
The imitation of jd.com e-commerce project is coming
『快速入门electron』之实现窗口拖拽
实战篇:Oracle 数据库标准版(SE)转换为企业版(EE)
20220603 Mathematics: pow (x, n)
[LZY learning notes dive into deep learning] 3.4 3.6 3.7 softmax principle and Implementation