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

Determine if Two Strings Are Close #90

Closed
Tracked by #101
fkdl0048 opened this issue Oct 15, 2024 · 0 comments
Closed
Tracked by #101

Determine if Two Strings Are Close #90

fkdl0048 opened this issue Oct 15, 2024 · 0 comments
Assignees
Labels
Milestone

Comments

@fkdl0048
Copy link
Owner

fkdl0048 commented Oct 15, 2024

class Solution {
public:
    bool closeStrings(string word1, string word2) {
        if (word1.size() != word2.size()) {
            return false;
        }

        vector<int> freq1(26, 0), freq2(26, 0);
        vector<int> exists1(26, 0), exists2(26, 0);

        for (char c : word1) {
            freq1[c - 'a']++;
            exists1[c - 'a'] = 1;
        }

        for (char c : word2) {
            freq2[c - 'a']++;
            exists2[c - 'a'] = 1;
        }

        if (exists1 != exists2) {
            return false;
        }

        sort(freq1.begin(), freq1.end());
        sort(freq2.begin(), freq2.end());

        return freq1 == freq2;
    }
};
  • 함정이 조금 있던 문제..
  • 이런 문제를 풀 땐, 문제에서 요구하는 풀이를 자료구조에 빗대어 생각하는게 중요한듯
  • 비교에서 문자열의 형태는 동일, 같다면 개수는 치환 가능 즉, 개수와 문자의 생김새를 분리하여 조건을 설정
@fkdl0048 fkdl0048 mentioned this issue Oct 15, 2024
7 tasks
@fkdl0048 fkdl0048 self-assigned this Oct 15, 2024
@fkdl0048 fkdl0048 added this to Todo Oct 15, 2024
@github-project-automation github-project-automation bot moved this to Todo in Todo Oct 15, 2024
@fkdl0048 fkdl0048 moved this from Todo to In Progress in Todo Oct 15, 2024
@fkdl0048 fkdl0048 added this to the LeetCode milestone Oct 15, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Todo Oct 15, 2024
@fkdl0048 fkdl0048 reopened this Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Done to Todo in Todo Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Todo Oct 15, 2024
@fkdl0048 fkdl0048 reopened this Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Done to Todo in Todo Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Todo Oct 15, 2024
@fkdl0048 fkdl0048 reopened this Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Done to Todo in Todo Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Todo Oct 15, 2024
@fkdl0048 fkdl0048 mentioned this issue Oct 15, 2024
75 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

1 participant