swift solution 12ms


  • 0
    S
    func arrayPairSum(_ nums: [Int]) -> Int {
        let tempArray = nums.sorted(by: <)
        var result = 0
        for value in tempArray.enumerated() {
            if(value.offset % 2 == 0){
                result+=value.element
            }
        }
        return result;
    }

Log in to reply
 

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