Created
November 21, 2016 06:01
-
-
Save tk0221/fd3035f3185d5b0ad81add93c6091ccc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @param {Integer} n | |
# @return {String[]} | |
def fizz_buzz(n) | |
tmp = [] | |
(1..n).each do |i| | |
if i % 3 == 0 | |
a = "Fizz" | |
a+= "Buzz" if i % 5 == 0 | |
tmp.push(a) | |
elsif i % 5 == 0 | |
tmp.push("Buzz") | |
else | |
tmp.push(i.to_s) | |
end | |
end | |
return tmp | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://leetcode.com/submissions/detail/83341083/