DEV Community

Discussion on: Daily Challenge #304 - Consecutive Letters

Collapse
 
edh_developer profile image
edh_developer • Edited

Bitflags in Go

func solve(testString string) bool {
    bitFlags := 0
    characters := []rune(testString)

    for _, r := range characters {
        bitFlags |= 1 << (r - 97) // rune('a') == 97
    }

    for (bitFlags & 1) == 0 {
        bitFlags >>= 1
    }

    return bitFlags == (1<<len(testString) - 1)
}
Enter fullscreen mode Exit fullscreen mode