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 return false.
  • s = "aabbb", sortedS = "aabbb", "aabbb" == "aabbb" so return true.
  • s = "bba", sortedS = "abb", "bba" != "abb" so return false.
func checkString(s string) bool {
    splitS := strings.Split(s, "")
    sort.Strings(splitS)
    return s == strings.Join(splitS, "")
}