Algorithm 🧑🏻‍💻/Leetcode

[Leetcode,c++] Valid Anagram

dkswnkk 2021. 11. 20. 10:52

문제

 

Valid Anagram - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

코드

class Solution {
public:
    bool isAnagram(string s, string t) {
        sort(s.begin(),s.end());
        sort(t.begin(),t.end());
        if(t==s) return true;
        else return false;
    }
};

 

풀이

Anagram 이란 한 문자열의 문자를 빠짐없이 사용하여 다른 문자열을 만들 수 있는 경우를 말합니다.

간단하게 정렬을 해준 후 비교해서 해결했습니다.