aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-07-28 13:07:09 +0000
committerterminaldweller <thabogre@gmail.com>2022-07-28 13:07:09 +0000
commit6f67b79b8ce67dbd2ddbfe845e2e2d120727bbb5 (patch)
treea6f600e22992d88d1c99238805273014920dfb57
parentupdates (diff)
downloadleetcode-6f67b79b8ce67dbd2ddbfe845e2e2d120727bbb5.tar.gz
leetcode-6f67b79b8ce67dbd2ddbfe845e2e2d120727bbb5.zip
update
Diffstat (limited to '')
-rw-r--r--242/go.mod3
-rw-r--r--242/main.go53
2 files changed, 56 insertions, 0 deletions
diff --git a/242/go.mod b/242/go.mod
new file mode 100644
index 0000000..99ad2d5
--- /dev/null
+++ b/242/go.mod
@@ -0,0 +1,3 @@
+module 242
+
+go 1.17
diff --git a/242/main.go b/242/main.go
new file mode 100644
index 0000000..49b6faf
--- /dev/null
+++ b/242/main.go
@@ -0,0 +1,53 @@
+package main
+
+func isAnagram_v_1(s string, t string) bool {
+ s_map := make(map[rune]int, len(s))
+ t_map := make(map[rune]int, len(t))
+ for _, character := range s {
+ s_map[character]++
+ }
+ for _, character := range t {
+ t_map[character]++
+ }
+
+ if len(s_map) != len(t_map) {
+ return false
+ }
+ for k, v := range s_map {
+ value, ok := t_map[k]
+ if !ok {
+ return false
+ }
+ if value != v {
+ return false
+ }
+ }
+
+ return true
+}
+
+func isAnagram(s string, t string) bool {
+ s_map := make([]int, 26)
+ t_map := make([]int, 26)
+ for _, character := range s {
+ s_map[int(character-'a')]++
+ }
+ for _, character := range t {
+ t_map[int(character-'a')]++
+ }
+
+ if len(s_map) != len(t_map) {
+ return false
+ }
+ for i := 0; i < 26; i++ {
+ if s_map[i] != t_map[i] {
+ return false
+ }
+ }
+
+ return true
+}
+
+func main() {
+ isAnagram("anagram", "nagaram")
+}