当前位置:网站首页>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)
边栏推荐
- Ind yff first week
- Softmax 回归(PyTorch)
- 2018 y7000 upgrade hard disk + migrate and upgrade black apple
- Ut2017 learning notes
- EFFICIENT PROBABILISTIC LOGIC REASONING WITH GRAPH NEURAL NETWORKS
- Pytorch ADDA code learning notes
- Several problems encountered in installing MySQL under MAC system
- Hands on deep learning pytorch version exercise solution -- implementation of 3-2 linear regression from scratch
- Jetson TX2 刷机
- 【SQL】一篇带你掌握SQL数据库的查询与修改相关操作
猜你喜欢

Simple real-time gesture recognition based on OpenCV (including code)

A super cool background permission management system

Leetcode - 5 longest palindrome substring

Leetcode - the k-th element in 703 data flow (design priority queue)

Deep Reinforcement learning with PyTorch

Knowledge map reasoning -- hybrid neural network and distributed representation reasoning

Introduction to deep learning linear algebra (pytorch)

Ut2015 learning notes

Policy Gradient Methods of Deep Reinforcement Learning (Part Two)

Anaconda installation package reported an error packagesnotfounderror: the following packages are not available from current channels:
随机推荐
[LZY learning notes dive into deep learning] 3.5 image classification dataset fashion MNIST
20220606 Mathematics: fraction to decimal
Leetcode - 5 longest palindrome substring
Leetcode刷题---278
Leetcode刷题---75
【SQL】一篇带你掌握SQL数据库的查询与修改相关操作
Leetcode-112: path sum
Leetcode刷题---832
3.3 Monte Carlo Methods: case study: Blackjack of Policy Improvement of on- & off-policy Evaluation
High imitation bosom friend manke comic app
20220610 other: Task Scheduler
Flutter 退出当前操作二次确认怎么做才更优雅?
Leetcode-100: same tree
六、MySQL之数据定义语言(一)
LeetCode - 900. RLE iterator
Ind FXL first week
Inverse code of string (Jilin University postgraduate entrance examination question)
Ind yff first week
Data preprocessing - Data Mining 1
Hands on deep learning pytorch version exercise solution - 2.3 linear algebra