当前位置:网站首页>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)
边栏推荐
- 神经网络入门之预备知识(PyTorch)
- Ut2017 learning notes
- Powshell's set location: unable to find a solution to the problem of accepting actual parameters
- QT creator uses OpenCV Pro add
- Configure opencv in QT Creator
- Ind FXL first week
- LeetCode - 715. Range module (TreeSet)*****
- Preliminary knowledge of Neural Network Introduction (pytorch)
- What did I read in order to understand the to do list
- Hands on deep learning pytorch version exercise solution - 2.6 probability
猜你喜欢

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

MySQL报错“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre”解决方法

Hands on deep learning pytorch version exercise answer - 2.2 preliminary knowledge / data preprocessing

2018 Lenovo y7000 black apple external display scheme

Rewrite Boston house price forecast task (using paddlepaddlepaddle)

Ut2016 learning notes

LeetCode - 900. RLE iterator

Ut2014 learning notes

安装yolov3(Anaconda)

Ut2014 supplementary learning notes
随机推荐
Hands on deep learning pytorch version exercise solution -- implementation of 3-2 linear regression from scratch
Leetcode刷题---1
CSDN, I'm coming!
High imitation wechat
An open source OA office automation system
权重衰退(PyTorch)
Free online markdown to write a good resume
Hands on deep learning pytorch version exercise answer - 2.2 preliminary knowledge / data preprocessing
安装yolov3(Anaconda)
20220604 Mathematics: square root of X
Content type ‘application/x-www-form-urlencoded; charset=UTF-8‘ not supported
20220605 Mathematics: divide two numbers
Boston house price forecast (tensorflow2.9 practice)
20220607其他:两整数之和
Stroke prediction: Bayesian
ThreadLocal原理及使用场景
Leetcode-513: find the lower left corner value of the tree
【毕业季】图匮于丰,防俭于逸;治不忘乱,安不忘危。
Leetcode刷题---374
20220606数学:分数到小数