Python: Why is this wrong? Is the testcase wrong??


  • -1
    N

    class Solution(object):
    def wordPattern(self, pattern, str):
    pattern = pattern
    str = str
    change = []
    linechange = []
    line = str.split(' ')

        if len(pattern) == len(line):
                    for i in range(len(pattern)-1):
                        if pattern[i] == pattern[i+1]:
                            change.append(0)
                        else:
                            change.append(1)
                
                        if line[i] == line[i+1]:
                            linechange.append(0)
                        else:
                            linechange.append(1)
                
                    if set(change) == set(linechange):
                        return True
                    else:
                        return False
    

    Input: "abba"
    "dog cat cat fish"
    Output: true
    Expected: false


  • 0

    the pattern here should be one-to-one related, so abba should be cat, dog, dog, cat


  • 0
    N

    @LHearen Thank you. I overseen it.


Log in to reply
 

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