Skip to content

Commit

Permalink
feat(ml):$263.ugly-number.md (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
ztianming authored Aug 25, 2020
1 parent 5e242e5 commit 9044cf4
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion problems/263.ugly-number.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Input is within the 32-bit signed integer range: [−231, 231 − 1].

## 代码

* 语言支持:JS, Python
* 语言支持:JS, C++, Java, Python

Javascript Code:

Expand Down Expand Up @@ -110,6 +110,43 @@ var isUgly = function(num) {
- 时间复杂度:$O(logN)$
- 空间复杂度:$O(logN)$

C++ Code:

```c++
class Solution {
public:
bool isUgly(int num) {
int ugly[] = {2,3,5};
for(int u : ugly)
{
while(num%u==0 && num%u < num)
{
num/=u;
}
}
return num == 1;
}
};
```
Java Code:
```java
class Solution {
public boolean isUgly(int num) {
int [] ugly = {2,3,5};
for(int u : ugly)
{
while(num%u==0 && num%u < num)
{
num/=u;
}
}
return num == 1;
}
}
```

Python Code:

```python
Expand Down

0 comments on commit 9044cf4

Please sign in to comment.