Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create priyagupta20044--c.md #608

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Day-17/Q1:Determine if two strings are close/priyagupta20044--c.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Solution {
public:
bool closeStrings(string word1, string word2) {
if (word1.length()!=word2.length()) return false;
map<char,int>m1;
map<char,int>m2;
map<int,int>m3;
map<int,int>m4;

for (int i=0;i<word1.length();i++) m1[word1[i]]++;
for (int i=0;i<word2.length();i++) m2[word2[i]]++;

for (auto iter: m1) m3[iter.second]++;
for (auto iter: m2) m4[iter.second]++;

for (auto iter:m1){
if (m2.find(iter.first) == m2.end()) return false;
}
for (auto iter:m3){
if (m4.find(iter.first) == m4.end()){
return false;
}
else{
if (iter.second != m4[iter.first])
return false;
}
}
return true;
}
};