We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 14ad0b9 commit 3e37de5Copy full SHA for 3e37de5
problems/fizz_buzz/solution.rs
@@ -1,18 +1,18 @@
1
impl Solution {
2
pub fn fizz_buzz(n: i32) -> Vec<String> {
3
- let mut ans: Vec<String> = Vec::new();
4
- for i in 1..n+1 {
5
- if i % 3 == 0 && i % 5 == 0 {
6
- ans.push(String::from("FizzBuzz"))
7
- } else if i % 3 == 0 {
8
- ans.push(String::from("Fizz"))
+ let mut v = Vec::with_capacity(n as usize);
+ for i in 1..(n + 1) {
+ if i % 15 == 0 {
+ v.push(String::from("FizzBuzz"))
9
} else if i % 5 == 0 {
10
- ans.push(String::from("Buzz"))
+ v.push(String::from("Buzz"))
+ } else if i % 3 == 0 {
+ v.push(String::from("Fizz"))
11
} else {
12
- ans.push(i.to_string())
+ v.push(i.to_string())
13
}
14
-
15
16
- ans
+ return v;
17
+
18
0 commit comments