funcquickOrder(arr []int) []int { length := len(arr) if length < 2 { return arr } res := []int{} flag := arr[0] mid := []int{} right := []int{} left := []int{} mid = append(mid, flag) for i := 1; i < length; i++ { if arr[i] > flag { right = append(right, arr[i]) } elseif arr[i] < flag { left = append(left, arr[i]) } else { mid = append(mid, arr[i]) } } right = quickOrder(right) left = quickOrder(left) res = append(append(left, mid...), right...) return res }
funcmidsearchmany(arr []int, target int) (firstleft int, lastright int) { length := len(arr) if length < 1 { return-1, -1 } left := 0 right := length for left < right { mid := (left + right) / 2 if arr[mid] >= target { right = mid } elseif arr[mid] < target { left = mid + 1 } } firstleft = right
left = 0 right = length for left < right { mid := (left+right)/2 + 1 if arr[mid] > target { right = mid - 1 } elseif arr[mid] <= target { left = mid } } lastright = left return }