Find the Median

  • + 0 comments

    My solution in golang:

    func findMedian(arr []int32) int32 {
        var median []int32
    
        sort.Slice(arr, func(i, j int) bool {
            return arr[i] < arr[j]
        })
    
        if len(arr)%2 == 0 {
            median = append(median, arr[len(arr)/2-1])
    
        } else {
            median = append(median, arr[len(arr)/2])
    
        }
        return median[0]
    
    }