본문 바로가기

Algorithm/Implementation

(C++) - LeetCode (easy) 242. Valid Anagram

반응형

https://leetcode.com/problems/valid-anagram/description/

 

Valid Anagram - LeetCode

Valid Anagram - Given two strings s and t, return true if t is an anagram of s, and false otherwise. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.   E

leetcode.com

간단 정렬 문제였습니다.

📕 풀이방법

📔 풀이과정

두 문자열을 사전순으로 정렬 후 같은지 여부를 반환합니다.


📕 Code

📔 C++

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

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.