You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Like the max function, argMax would return the index of max element from a slice. For example:
func argMax(nums []int64) int {
if len(nums) == 0 {
panic("error")
}
var maxNum int64
var maxIndex int
for i, num := range nums {
if i == 0 {
maxNum = num
maxIndex = 0
continue
}
if num > maxNum {
maxNum = num
maxIndex = i
}
}
return maxIndex
}
If there are duplicate occurrences of max element, only return the first one.
The text was updated successfully, but these errors were encountered:
thoas
changed the title
[feature request] how about adding argMax which return the index of max element from a slice ?
how about adding argMax which return the index of max element from a slice ?
Dec 26, 2022
Like the max function, argMax would return the index of max element from a slice. For example:
If there are duplicate occurrences of max element, only return the first one.
The text was updated successfully, but these errors were encountered: