diff --git a/problems/1365.有多少小于当前数字的数字.md b/problems/1365.有多少小于当前数字的数字.md index 76eb3d36..011e4beb 100644 --- a/problems/1365.有多少小于当前数字的数字.md +++ b/problems/1365.有多少小于当前数字的数字.md @@ -149,7 +149,35 @@ class Solution: res[i] = hash[num] return res ``` + Go: +```go +func smallerNumbersThanCurrent(nums []int) []int { + // map,key[数组中出现的数] value[比这个数小的个数] + m := make(map[int]int) + // 拷贝一份原始数组 + rawNums := make([]int,len(nums)) + copy(rawNums,nums) + // 将数组排序 + sort.Ints(nums) + // 循环遍历排序后的数组,值为map的key,索引为value + for i,v := range nums { + _,contains := m[v] + if !contains { + m[v] = i + } + + } + // 返回值结果 + result := make([]int,len(nums)) + // 根据原始数组的位置,存放对应的比它小的数 + for i,v := range rawNums { + result[i] = m[v] + } + + return result +} +``` JavaScript: ```javascript