My code work well on my PC, but judge wrong , someone know why?

  • 0

    class Solution(object):
    def wordPattern(self, pattern, str):
    :type pattern: str
    :type str: str
    :rtype: bool
    string_dict = {}
    items = pattern.split(' ')
    for i in range(len(items)):
    if items[i] not in string_dict:
    string_dict[items[i]] = str[i]
    elif string_dict[items[i]] != str[i]:
    return False
    unique_dict = {}
    for item in string_dict:
    if string_dict[item] not in unique_dict:
    return False
    return True

Log in to reply

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