1 回答
TA贡献1934条经验 获得超2个赞
您可以使用地图来存储和比较键:
package main
import (
"fmt"
)
type Column struct {
Name string `json:"name"`
Type string `json:"type"`
}
func check(c1, c2 []*Column) bool {
m := make(map[string]string)
for _, col := range c1 {
m[col.Name] = col.Type
}
for _, col := range c2 {
if t, found := m[col.Name]; found && t != col.Type {
return true
}
}
return false
}
func main() {
a := []*Column{
{Name: "a", Type: "int"},
{Name: "b", Type: "int"},
}
b := []*Column{
{Name: "a", Type: "int"},
{Name: "c", Type: "string"},
}
c := []*Column{
{Name: "a", Type: "string"},
{Name: "d", Type: "int"},
}
fmt.Println(check(a, b)) //false
fmt.Println(check(a, c)) //true
fmt.Println(check(b, c)) //true
}
- 1 回答
- 0 关注
- 108 浏览
添加回答
举报