pra*_*nay 1 python string algorithm
如何检查字符串,对于其中的每个字符,存在字母小于它之前的所有字符,例如aab是正确的而aacb不是,因为第二种情况,我们有'c'但是'b'是不在场之前.aac也不正确,因为它在'c'之前没有'b'.
伪代码.适用于同样的情况abac.
max = 'a' - 1 // character immediately before 'a'
for char in string
if char > max + 1
// bad string, stop algorithm
end
if char > max
max = char
end
end
Run Code Online (Sandbox Code Playgroud)
我们的想法是,我们需要在之前按字母顺序检查当前字符之前的字符.如果我们有性格e,现在和d以前发生的,那么c,b并且a做了.
| 归档时间: |
|
| 查看次数: |
148 次 |
| 最近记录: |