daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Feb 17th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. const (
  6.     maxInt = int(^uint(0) >> 1)
  7.     minInt = -maxInt - 1
  8. )
  9.  
  10. func isMerge(a1, a2 []int) bool {
  11.     min1, max1 := maxInt, minInt
  12.     for _, e1 := range a1 {
  13.         if min1 > e1 {
  14.             min1 = e1
  15.         }
  16.         if max1 < e1 {
  17.             max1 = e1
  18.         }
  19.     }
  20.  
  21.     for _, e2 := range a2 {
  22.         if e2 == min1-1 || e2 == max1+1 {
  23.             return true
  24.         }
  25.     }
  26.  
  27.     return false
  28. }
  29.  
  30. func main() {
  31.     a1 := []int{100, 101}
  32.     a2 := []int{103, 104, 102}
  33.     a3 := []int{103, 104, 105}
  34.     fmt.Println(a1, a2, isMerge(a1, a2))
  35.     fmt.Println(a1, a3, isMerge(a1, a3))
  36.  
  37.     a4 := []int{222, 221, 220, 219}
  38.     a5 := []int{221, 222, 223, 225, 224}
  39.     fmt.Println(a4, a5, isMerge(a4, a5))
  40. }
  41.    
  42. [100 101] [103 104 102] true
  43. [100 101] [103 104 105] false
  44. [222 221 220 219] [221 222 223 225 224] true
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top