Skip to content

Instantly share code, notes, and snippets.

@nicain
Last active October 10, 2022 21:22
Show Gist options
  • Save nicain/fb72763bd304f708700fcb0539d741ee to your computer and use it in GitHub Desktop.
Save nicain/fb72763bd304f708700fcb0539d741ee to your computer and use it in GitHub Desktop.
HW
def merge(self, intervals):
out = []
for i in sorted(intervals, key=lambda i: i.start):
if out and i.start <= out[-1].end:
out[-1].end = max(out[-1].end, i.end)
else:
out += i,
return out
class Solution:
def fizzBuzz(self, n):
"""
:type n: int
:rtype: List[str]
"""
# ans list
ans = []
for num in range(1,n+1):
divisible_by_3 = (num % 3 == 0)
divisible_by_5 = (num % 5 == 0)
if divisible_by_3 and divisible_by_5:
# Divides by both 3 and 5, add FizzBuzz
ans.append("FizzBuzz")
elif divisible_by_3:
# Divides by 3, add Fizz
ans.append("Fizz")
elif divisible_by_5:
# Divides by 5, add Buzz
ans.append("Buzz")
else:
# Not divisible by 3 or 5, add the number
ans.append(str(num))
return ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment