Leetcode Note: Go - Count Asterisks

Count Asterisks - LeetCode
https://leetcode.com/problems/count-asterisks/

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

回答

Go xor - Count Asterisks - LeetCode
https://leetcode.com/problems/count-asterisks/solutions/2272171/go-xor/

func countAsterisks(s string) int {
    res, pipe := 0, 0
    
    for _, v := range s {
        if v == '|' {
            pipe ^= 1
        }
        
        if v == '*' && pipe == 0 {
            res++
        }
    }
    
    return res
}