Skip to content

Instantly share code, notes, and snippets.

@jacygao
Created September 1, 2022 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacygao/c06c05aae0afa859e11e6af85a25e7fc to your computer and use it in GitHub Desktop.
Save jacygao/c06c05aae0afa859e11e6af85a25e7fc to your computer and use it in GitHub Desktop.
isPermutation.go
package main
import "fmt"
func main() {
s1 := "abcdefg%!~~"
s2 := "ac%dgf!b~e~"
fmt.Println(isPermutation(s1, s2))
}
func isPermutation(s1, s2 string) bool {
if len(s1) != len(s2) {
return false
}
sum1, sum2 := byte(0), byte(0)
for i := 0; i < len(s1); i++ {
sum1 += s1[i]
sum2 += s2[i]
}
return sum1 == sum2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment