Swift Solution


  • 0
    S
    guard !nums.isEmpty else { return [] }
    
    let sortedNums = nums.sorted{ $0 > $1 }
      
      var pos = 1
      var dict: [Int: String] = [:]
      sortedNums.forEach {
        switch pos {
            case 1:
                  dict[$0] = "Gold Medal"
            case 2:
                  dict[$0] = "Silver Medal"
            case 3:
                  dict[$0] = "Bronze Medal"
            default:
                dict[$0] = String(pos)
            
        }
        pos += 1
      }
      
      return nums.map {
        return dict[$0] ?? "0"
      }
    

Log in to reply
 

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