Created
June 8, 2021 02:48
-
-
Save mumunuu/f039366bda8a6ee98d61c005695f8691 to your computer and use it in GitHub Desktop.
1869. Longer Contiguous Segments of Ones than Zeros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func checkZeroOnes(s string) bool { | |
oneLen := getLongest(s, "1") | |
zeroLen := getLongest(s, "0") | |
if oneLen > zeroLen { | |
return true | |
} | |
return false | |
} | |
func getLongest(s, flag string) int { | |
for i := len(s); i > 0; i-- { | |
if strings.Index(s, strings.Repeat(flag, i)) != -1 { | |
return i | |
} | |
} | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment