Skip to content

Commit 9093aef

Browse files
committed
Day 20
1 parent 038889d commit 9093aef

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Interview Bit/Math/FizzBuzz.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
vector<string> Solution::fizzBuzz(int A) {
2+
3+
vector<string> res;
4+
for(int i=1;i<=A;i++)
5+
{
6+
if(i%3==0&&i%5==0)
7+
res.push_back("FizzBuzz");
8+
else if(i%3==0)
9+
res.push_back("Fizz");
10+
else if(i%5==0)
11+
res.push_back("Buzz");
12+
else
13+
res.push_back(to_string(i));
14+
}
15+
16+
return res;
17+
}
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
int Solution::hammingDistance(const vector<int> &A) {
2+
3+
vector<int> bin_array(32,0);
4+
const int mod=1000000007;
5+
int i;
6+
for(i=0;i<A.size();i++)
7+
{
8+
int index=0;
9+
int num=A[i];
10+
while(num>0)
11+
{
12+
bin_array[index]+=(num&1);
13+
num=num>>1;
14+
index++;
15+
}
16+
}
17+
int ans=0;
18+
for(i=0;i<32;i++)
19+
{
20+
ans=(ans+((bin_array[i])*(A.size()-bin_array[i])*2))%mod;
21+
}
22+
23+
return ans;
24+
}
25+

0 commit comments

Comments
 (0)