One-line simple Ruby solution

  • 0
    def find_the_difference(s, t)
        return s.chars.concat(t.chars).map!(&:ord).reduce(:^).chr

    Basically, you put the strings together, get the int value of each character, xor each value to find the odd one out, and get the char value of it.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.