Python: Eliminating the 'u' for Unicode + Solution


  • 0
    D

    I was getting a random 'u' in my solution and found it converting to utf-8 fixed the problem in case anyone was struggling. First time getting a problem 100% by myself, so I'm pretty proud.

    Not the most efficient way and can be shortened.

    class Solution(object):
    def findTheDifference(self, s, t):
    s=s.encode("utf-8")
    t=t.encode("utf-8")
    a = [s[x] for x in range(0,len(s))]
    b = [t[x] for x in range(0,len(t))]

        for x in a:     #a b c d
            if x in b:  #a b c d e
                b.remove(x)
        for i in range(0,len(b)):
            return b[i]

Log in to reply
 

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