why my solution is a bit off?


  • 0
    Y

    I got this as the sample answer result, which is a flip of [[0, 1], [1, 0], [3, 2], [2, 4]]
    [[0, 1], [1, 0]]
    [[0, 1], [1, 0], [2, 4], [3, 2]]
    although I ran into run-time error, but I am curious that, isn't this solution also kind of work? there is something I am missing from the program I am trying to address, but I cannot tell

    def palindromePairs(words):
        """
        :type words: List[str]
        :rtype: List[List[int]]
        """
        def evaluate(str):
            for i in range(len(str)/2):
                if str[i]!=str[-i-1]:
                    return 0
            return 1
    
        result_set=[]
        for i, word in enumerate(words):
            for j in range(len(words)):
                if i!=j:
                    str=words[i]+words[j]
                    if evaluate(str):
                        result_set.append([i, j])
        return result_set
    
    
    print palindromePairs(["bat", "tab", "cat"])
    print palindromePairs(["abcd", "dcba", "lls", "s", "sssll"])
    

Log in to reply
 

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