Skip to content

Commit 027fe9f

Browse files
committed
Adding Simple Solution - Problem - 263 - Ugly Number
1 parent 7e84cae commit 027fe9f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Ugly_Number/SimpleSolution.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
##==================================
2+
## Leetcode
3+
## Student: Vandit Jyotindra Gajjar
4+
## Year: 2020
5+
## Problem: 263
6+
## Problem Name: Ugly Number
7+
##===================================
8+
#
9+
#Write a program to check whether a given number is an ugly number.
10+
#
11+
#Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.
12+
#
13+
#Example 1:
14+
#
15+
#Input: 6
16+
#Output: true
17+
#Explanation: 6 = 2 × 3
18+
#Example 2:
19+
#
20+
#Input: 8
21+
#Output: true
22+
#Explanation: 8 = 2 × 2 × 2
23+
#Example 3:
24+
#
25+
#Input: 14
26+
#Output: false
27+
#Explanation: 14 is not ugly since it includes another prime factor 7.
28+
class Solution:
29+
def isUgly(self, num):
30+
if num == 0: #Condition-check: If num is zero
31+
return False #We return false
32+
for i in [2, 3, 5]: #Loop through 2, 3, 5
33+
while num % i == 0: #Loop till condition met
34+
num /= i #Update number by dividing by i
35+
return num == 1 #Return true or false if the number will be 1

0 commit comments

Comments
 (0)