From c7564092e2d6cea76f3a7fd0e5ef01d51a550494 Mon Sep 17 00:00:00 2001 From: "lovesikka062@gmail.com" Date: Wed, 22 Oct 2025 13:52:41 +0530 Subject: [PATCH] Added Leetcode 242 --- 242. Valid Anagram.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 242. Valid Anagram.cpp diff --git a/242. Valid Anagram.cpp b/242. Valid Anagram.cpp new file mode 100644 index 0000000..a7a28b8 --- /dev/null +++ b/242. Valid Anagram.cpp @@ -0,0 +1,19 @@ +class Solution { +public: + bool isAnagram(string s, string t) { + if(s.length() != t.length()) return false; + + int count[26] = {0}; + + for(int i = 0; i < s.length(); i++) { + count[s[i]-'a']++; + count[t[i]-'a']--; + } + + for(int i = 0; i < 26; i++) { + if(count[i] != 0) return false; + } + + return true; + } +};