Leetcode Note: Go - Crawler Log Folder

Crawler Log Folder - LeetCode
https://leetcode.com/problems/crawler-log-folder/

  • Go 言語で取り組んだメモ

回答

func minOperations(logs []string) int {
    result := 0
    
    for _, log := range logs {
        switch {
        case log == "../":
            if result - 1 > 0 {
                result--
            } else {
                result = 0
            }
        case log != "./":
            result++
        }
    }
    
    return result
}