Created
September 1, 2022 03:12
-
-
Save jacygao/c06c05aae0afa859e11e6af85a25e7fc to your computer and use it in GitHub Desktop.
isPermutation.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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