We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
funccavityMap(grid:[String])->[String]{// Write your code hereifgrid.first!.count<3{returngrid}vargridUTF8:[[UInt8]]=grid.map{[UInt8]($0.utf8)}letgridMaxIndex:Int=gridUTF8.count-1letgridContentMaxIndex:Int=gridUTF8.first!.count-1forindex1in1...gridMaxIndex-1{forindex2in1...gridContentMaxIndex-1{letcurrentGrid:UInt8=gridUTF8[index1][index2]letisHValid:Bool=gridUTF8[index1][index2-1]<currentGrid&&gridUTF8[index1][index2+1]<currentGridletisVValid:Bool=gridUTF8[index1-1][index2]<currentGrid&&gridUTF8[index1+1][index2]<currentGridifisHValid&&isVValid{gridUTF8[index1][index2]=88continue}}}returngridUTF8.map{String(bytes:$0,encoding:String.Encoding.utf8)??""}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cavity Map
You are viewing a single comment's thread. Return to all comments →
SWIFT