Skip to content

Latest commit

 

History

History
90 lines (69 loc) · 2.76 KB

_2451. Odd String Difference.md

File metadata and controls

90 lines (69 loc) · 2.76 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : September 25, 2024

Last updated : September 25, 2024


Related Topics : Array, Hash Table, String

Acceptance Rate : 60.37 %


Solutions

Python

# Extremly inefficient but one liners are funny lol

class Solution:
    def oddString(self, words: List[str]) -> str:
        return {
            tuple(ord(word[i]) - ord(word[i - 1]) 
                  for i in range(1, len(word)))
            :
            word 
            for word in words
        }[
            sorted(list(Counter(tuple(ord(word[i]) - ord(word[i - 1]) 
                                      for i in range(1, len(word))) 
                                      for word in words)), 
                   key=lambda x: Counter(tuple(ord(word[i]) - ord(word[i - 1]) 
                                               for i in range(1, len(word))) 
                                               for word in words)[x])
            [0]
        ]
class Solution:
    def oddString(self, words: List[str]) -> str:
      return {tuple(ord(word[i]) - ord(word[i - 1]) for i in range(1, len(word))) : word for word in words}[sorted(list(Counter(tuple(ord(word[i]) - ord(word[i - 1]) for i in range(1, len(word))) for word in words)), key=lambda x: Counter(tuple(ord(word[i]) - ord(word[i - 1]) for i in range(1, len(word))) for word in words)[x])[0]]
class Solution:
    def oddString(self, words: List[str]) -> str:
        firstTup   = None
        foundTwice = False
        otherWord  = None

        for i, word in enumerate(words) :
            currTup = tuple(ord(word[i]) - ord(word[i - 1]) 
                            for i in range(1, len(word)))

            if not firstTup :
                firstTup = currTup
                continue

            if firstTup == currTup :
                if otherWord :
                    return otherWord
                foundTwice = True
                continue

            if not otherWord :
                if foundTwice :
                    return word
                otherWord = word
                continue

            return words[0]