We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
func ContainsAll(slice1 []string, slice2 []string) bool { // 如果长度不同,则直接返回 false if len(slice1) != len(slice2) { return false }
// 创建两个 map 记录每个切片中元素的频率 freq1 := make(map[string]int) freq2 := make(map[string]int) for _, element := range slice1 { freq1[element]++ } for _, element := range slice2 { freq2[element]++ } // 比较两个频率 map 是否相同 for key, count := range freq1 { if freq2[key] != count { return false } } return true
}
这个函数旨在比较两个 slice,里面的元素是否相等而不在意顺序
The text was updated successfully, but these errors were encountered:
func ContainsAll(slice1 []string, slice2 []string) bool { // 如果长度不同,则直接返回 false if len(slice1) != len(slice2) { return false } // 创建两个 map 记录每个切片中元素的频率 freq1 := make(map[string]int) freq2 := make(map[string]int) for _, element := range slice1 { freq1[element]++ } for _, element := range slice2 { freq2[element]++ } // 比较两个频率 map 是否相同 for key, count := range freq1 { if freq2[key] != count { return false } } return true } 这个函数旨在比较两个 slice,里面的元素是否相等而不在意顺序
@J4sonZ v2分支之前已经添加了EqualUnordered, 下个版本会发布
Sorry, something went wrong.
No branches or pull requests
func ContainsAll(slice1 []string, slice2 []string) bool {
// 如果长度不同,则直接返回 false
if len(slice1) != len(slice2) {
return false
}
}
这个函数旨在比较两个 slice,里面的元素是否相等而不在意顺序
The text was updated successfully, but these errors were encountered: