Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6699908

Browse files
authored
Add 412_Fizz_Buzz (qiyuangong#20)
* Add 412_Fizz_Buzz CPP solution, by @ruchit2801
1 parent f8a6d76 commit 6699908

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cpp/412_Fizz_Buzz.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#define pb push_back
2+
class Solution {
3+
public:
4+
vector<string> fizzBuzz(int n) {
5+
int i;
6+
vector<string> s;
7+
for(i=0;i<n;i++){
8+
if((i+1)%15==0)s.pb("FizzBuzz");
9+
else if((i+1)%5==0)s.pb("Buzz");
10+
else if((i+1)%3==0)s.pb("Fizz");
11+
else s.pb(to_string(i+1));
12+
}
13+
return s;
14+
}
15+
};

0 commit comments

Comments
 (0)