Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- const (
- maxInt = int(^uint(0) >> 1)
- minInt = -maxInt - 1
- )
- func isMerge(a1, a2 []int) bool {
- min1, max1 := maxInt, minInt
- for _, e1 := range a1 {
- if min1 > e1 {
- min1 = e1
- }
- if max1 < e1 {
- max1 = e1
- }
- }
- for _, e2 := range a2 {
- if e2 == min1-1 || e2 == max1+1 {
- return true
- }
- }
- return false
- }
- func main() {
- a1 := []int{100, 101}
- a2 := []int{103, 104, 102}
- a3 := []int{103, 104, 105}
- fmt.Println(a1, a2, isMerge(a1, a2))
- fmt.Println(a1, a3, isMerge(a1, a3))
- a4 := []int{222, 221, 220, 219}
- a5 := []int{221, 222, 223, 225, 224}
- fmt.Println(a4, a5, isMerge(a4, a5))
- }
- [100 101] [103 104 102] true
- [100 101] [103 104 105] false
- [222 221 220 219] [221 222 223 225 224] true
Add Comment
Please, Sign In to add comment