leetcode412. Fizz Buzz
2022-03-14 12:55 作者:您是打尖兒還是住店呢 | 我要投稿
Given an integer?n
, return?a string array?answer
?(1-indexed) where:
answer[i] == "FizzBuzz"
?if?i
?is divisible by?3
?and?5
.answer[i] == "Fizz"
?if?i
?is divisible by?3
.answer[i] == "Buzz"
?if?i
?is divisible by?5
.answer[i] == i
?(as a string) if none of the above conditions are true.
?
Example 1:
Input: n = 3Output: ["1","2","Fizz"]
Example 2:
Input: n = 5Output: ["1","2","Fizz","4","Buzz"]
Example 3:
Input: n = 15Output: ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
?
Constraints:
1 <= n <= 104
Runtime:?2 ms, faster than?68.26%?of?Java?online submissions for?Fizz Buzz.
Memory Usage:?48.9 MB, less than?7.70%?of?Java?online submissions for?Fizz Buzz.
沒啥好說的,主要就是判斷一下。
標簽: