336. Palindrome Pairs

336. Palindrome Pairs

class Solution:
    def palindromePairs(self, words: List[str]) -> List[List[int]]:
        
        def isPalindrome(word):
            left = 0
            right = len(word) - 1

            while left < right:
                if word[left] != word[right]:
                    return False
                left += 1
                right -= 1
            return True

        res = []
        i = 0
        
        while i < len(words):
            j = 0
            while j < len(words):
                if i != j:
                    word = words[i] + words[j]
                    if isPalindrome(word):
                        res.append([i, j])
                j += 1
            i += 1
        return res