알고리즘 5일차

Panther·2021년 7월 13일
0

Algorithm

목록 보기
5/15
post-custom-banner
func solution(_ win_lose: [Int]) -> Int {
    
    var winLose = win_lose
    var intArray = [[Int]]()
    var resultArray = [Int]()
    var result = Int()
    
    while winLose.count != 0 {
        
        var firstZeroIndex = Int()
        var temp = [Int]()
        
        if let zeroIndex = winLose.firstIndex(of: 0) {
            firstZeroIndex = zeroIndex
        }
        
        for i in 0...firstZeroIndex {
            temp.append(winLose[i])
        }
        
        intArray.append(temp)
        
        for _ in 0...firstZeroIndex {
            winLose.removeFirst()
        }
        
    }
    
    for i in 0..<intArray.count {
        resultArray.append(intArray[i].reduce(0) { $0 + $1 })
    }
    
    if let tempResult = resultArray.max() {
        result = tempResult
    }
    
    return result

}
post-custom-banner

0개의 댓글