TalkGo 算法之美第一期来啦!!!

func getTwoNumWithSameSumAndMinMult(nums []int, S int) (int, int) {
kv := make(map[int]struct{})
for _, num := range nums {
kv[num] = struct{}{}
}

num1, num2 := -1, -1
min := math.MaxInt32
for _, num :=range nums {
	if num > S/2 {
		break
	}
	if _,ok := kv[S-num]; ok {
		if num * (S-num) < min {
			min = num * (S-num)
			num1 = num
			num2 = S -num
		}
	}
}

return num1, num2

}

func medianNum(nums []int) int {
//1: 找到起点
//2: 向前移动数组大小的一半
i := 0
length := len(nums)

for nums[i%length] <= nums[(i+1)%length] {}
start := (i+1)%length

for i := 1; i <= length/2; i++ {
	start = (start+1)%length
}
if length % 2 != 0 {
	return nums[start]
}
return (nums[start] + nums[start-1])/2

}