4 ms·
abcba is a palindrome
by HeyImAlex 5y ago
abcba is a palindrome
- loup-vaillant 5y agoYes it is, and it wouldn't fail my algorithm: a -> not in set -> add a (a) b -> not in set -> add b (ab) c -> not in set -> add c (abc) b -> in set -> remove b (ac) a -> in set -> remove a (c) Set has 1 <= 1 element -> return OK (Of course, "aabcb" would return yes as well, but that's the whole point: we're not asking whether a string is a palindrome, but whether any one of its permutations is.)