Skip to content

Commit ee1fe13

Browse files
Added solution
1 parent 9fc747c commit ee1fe13

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

defragmenting_ip_address.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
string split(string s){
4+
string new_str = "";
5+
for(auto it=s.begin(); it!=s.end();it++){
6+
if(*it != '.')
7+
new_str+= *it;
8+
else if(*it == '.')
9+
new_str += "[.]";
10+
}
11+
return new_str;
12+
}
13+
string defangIPaddr(string address){
14+
return split(address);
15+
}
16+
};

hamming_distance.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int hammingDistance(int x, int y) {
4+
int op1, op2;
5+
long long int distance = 0;
6+
while(x > 0 || y > 0){
7+
op1 = x % 2;
8+
op2 = y % 2;
9+
distance += (op1 ^ op2);
10+
x /= 2;
11+
y /= 2;
12+
}
13+
cout<<distance<<"\n";
14+
cout<<x<<y;
15+
return distance;
16+
}
17+
};

0 commit comments

Comments
 (0)