#306. 判断字符串xy平衡性
判断字符串xy平衡性
xy-Balanced String
Background
Dawei and Xiaoxiao are studying string properties. They have defined a special type of string balance.
Problem Description
We'll say that a String is xy-balanced if for all the 'x' chars in the string, there exists a 'y' char somewhere later in the string. So "xxy" is balanced, but "xyx" is not. One 'y' can balance multiple 'x's. Return true if the given string is xy-balanced.
Input Format
Input is given from standard input in the following format.
s
Output Format
Output is printed to standard output in the following format.
trueorfalse
Sample
aaxbby
true
aaxbb
false
yaaxbb
false
Sample Explanation
For Sample 1, the string is "aaxbby". The last 'y' is at index 5. There are no 'x's after it, so it is xy-balanced. For Sample 2, the string is "aaxbb". There are no 'y's in the string, but there are 'x's, so it is not xy-balanced. For Sample 3, the string is "yaaxbb". The last 'y' is at index 0. There are 'x's after it (at indices 2 and 3), so it is not xy-balanced.
Constraints
Time limit: 1s, Memory limit: 1024KiB for each test case.