Work in Xcode but not in OJ


  • 0

    Somebody tell me what wrong with this solution. I don't understand why I should use UnsafeMutablePointer<Double> if result is [Double]

    class Solution {
        func medianSlidingWindow(_ nums: [Int], _ k: Int) -> [Double] {
            let limit = nums.count - k
            var value = [Double]()
            for i in 0...limit {
                let window = Array(nums.dropLast(limit - i).dropFirst(i)).sorted()
                let center:Int = ((k + 1) / 2) - 1
                if k % 2 == 0 {
                    value.append(Double(window[center] + window[min(center + 1, k)]) / 2.0)
                } else {
                    value.append(Double(window[center]))
                }
            }
            return value
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.