1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| func countSmaller(nums []int) []int { // 定义一数组 result := make([]int, len(nums))
if len(nums) == 0 {return result}
// 双重循环 for idx, value := range nums{ tmp := 0 for i := idx + 1; i < len(nums); i ++ { if nums[i] < value{ tmp ++ } } // fmt.Println("tmp:", tmp, "idx:", idx) result[idx] = tmp }
return result }
|