1003. Check If Word Is Valid After Substitutions - notruilin/LeetCode GitHub Wiki

index = S.find("abc")

If there is no "abc" in S, index == -1

index = S.index("abc")

If there is no "abc" in S, it will throw an exception

Another solution is stack, pop "a" and "b" when each time we meet "c" If the top of the stack aren't "b" and "a", return False