funcwiggleMaxLength(nums []int)int { iflen(nums) < 2 { returnlen(nums) } res := 1 pre := nums[1] - nums[0] if pre != 0 { res++ } for i := 2; i < len(nums); i++ { cur := nums[i] - nums[i-1] if pre >= 0 && cur < 0 || pre <= 0 && cur > 0 { res++ pre = cur } } return res }
funceraseOverlapIntervals(intervals [][]int)int { sort.Slice(intervals, func(a, b int)bool { return intervals[a][0] < intervals[b][0] }) res := 0 right := intervals[0][1]
for i := 1; i < len(intervals); i++ { if intervals[i][0] < right { right = min(right, intervals[i][1]) res++ } else { right = intervals[i][1] } } return res }
funcpartitionLabels(s string) []int { var res []int bMap := make(map[byte]int) b := []byte(s) for i := 0; i < len(b); i++ { bMap[b[i]] = i } var maxPos, lenth int for i, v := range b { lenth++ if bMap[v] > maxPos { maxPos = bMap[v] } if i == maxPos { res = append(res, lenth) lenth = 0 } } return res }