Skip to content

Commit

Permalink
Merge pull request #75 from zrcoder/master
Browse files Browse the repository at this point in the history
simplify the code of anagram
  • Loading branch information
plutov authored Jun 13, 2024
2 parents d65d98e + 8bea258 commit 9e3228f
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions anagram/anagram.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package anagram

import (
"sort"
"slices"
"strings"
"unicode"
)

type MyRune []rune

func (r MyRune) Len() int { return len(r) }
func (r MyRune) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
func (r MyRune) Less(i, j int) bool { return r[i] < r[j] }

func Normalize(s string) string {
var r MyRune
var r []rune
for _, b := range s {
b = unicode.ToLower(b)
if b >= 'a' && b <= 'z' {
r = append(r, b)
}
}
sort.Sort(r)
slices.Sort(r)
return string(r)
}

Expand Down

0 comments on commit 9e3228f

Please sign in to comment.