Valid Anagram

Yohan Kim·2021년 9월 25일
0

problem

두 문자가 anagram 인지 검사하는 코드입니다.

anagram이란 주어진 문자의 순서만 변형된 형태를 말합니다.

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

solution

//problem no : 242
class Solution {
public:
    bool isAnagram(string s, string t) {
        
        if(s.length() != t.length()){return false;}
        
        int ans[26] = {0,};
        for(int i=0;i<s.length();i++){
            ans[s[i]-'a'] += 1;
            ans[t[i]-'a'] -= 1;
        }
        for(int i: ans){
            if(i){
                return false;
            }
        }
        return true;
    }
};
profile
안녕하세요 반가워요!

0개의 댓글

관련 채용 정보

Powered by GraphCDN, the GraphQL CDN