Python method with 'try' and '.remove' instead of hashtable (slow though)


  • 0
    P
            ss=list(s)
            tt=list(t)
            for i in ss:
                try:
                    tt.remove(i)
                except ValueError:
    # check if this particular i is in ss but not in tt for this time
                    return False
            if not tt: return True
    # after we removed every item in ss, if everything in tt is also removed, then True
            return False
    # If there are still something in tt, then False
    

Log in to reply
 

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