From 7c60dee83b436e8e8a667bf9f191beced8de4fc3 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Mon, 10 Mar 2025 00:36:13 -0600 Subject: chore: move cpp and rust code to directory --- other/valid_anagram.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 other/valid_anagram.cpp (limited to 'other/valid_anagram.cpp') diff --git a/other/valid_anagram.cpp b/other/valid_anagram.cpp new file mode 100644 index 0000000..2c2586e --- /dev/null +++ b/other/valid_anagram.cpp @@ -0,0 +1,29 @@ +#include "leetcode.h" + +class Solution { +public: + bool isAnagram(string s, string t) { + if (s == t) + return true; + if (s.size() != t.size()) + return false; + unordered_map up; + for (int i = 0; i < s.size(); i++) { + up[s[i]]++; + up[t[i]]--; + } + for (auto it : up) + if (it.second) + return false; + return true; + } +}; + +int main() { + Solution obj; + string s = "anagram", t = "nagaram"; + if (obj.isAnagram(s, t)) + cout << "true"; + else + cout << "false"; +} -- cgit v1.2.3