2451. Odd String Difference
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : September 25, 2024
Last updated : September 25, 2024
Related Topics : Array, Hash Table, String
Acceptance Rate : 60.37 %
# 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]