Thursday, July 23, 2015

is any arrangement of string palindrome

(s):
    if s == null:
        throw
    if s == "":
        return false
    set oddchars = new
    for i = 0, i < s.length, i++:
        // break out if rest of string cannot get oddchars's count down to 1 
        if oddchars.count() - (s.length - i) > 1:
            break
        c = a[i]
        if oddchars.has(c):
            oddchars.remove(c)
        else:
            oddchars.add(c)
    return oddchars.count() <= 1
[Hat tip to LV]

No comments:

Post a Comment