One minute
Leetcode 2124
2124. Check if All A’s Appears Before All B’s
The idea of my solution is pretty simple. If the sorted version of s equals the non sorted version of s we know that every "a" comes before every "b". Some examples could be:
s = "abab",sortedS = "aabb","abab" != "aabb"so returnfalse.s = "aabbb",sortedS = "aabbb","aabbb" == "aabbb"so returntrue.s = "bba",sortedS = "abb","bba" != "abb"so returnfalse.
func checkString(s string) bool {
splitS := strings.Split(s, "")
sort.Strings(splitS)
return s == strings.Join(splitS, "")
}
Read other posts