SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // MinMax return min and max O(1.5n)
  2. func MinMax(A []int) (min int, max int) {
  3.     if len(A) < 1 {
  4.         return 0, 0
  5.     }
  6.     min, max = A[0], A[0]
  7.     mi, ma := 0, 0
  8.     for i := 1; i < len(A)-1; i += 2 {
  9.         if A[i] > A[i+1] {
  10.             mi, ma = A[i+1], A[i]
  11.         } else {
  12.             mi, ma = A[i], A[i+1]
  13.         }
  14.         if ma > max {
  15.             max = ma
  16.         }
  17.         if mi < min {
  18.             min = mi
  19.         }
  20.     }
  21.     return min, max
  22. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top