2547. Odd String Difference
My accepted Python solution to LeetCode problem 2547, Odd String Difference, running in 1ms.
- Difficulty: Easy
- Python
- Runtime 1ms
- Memory 17.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 1ms, memory 17.3MB, accepted 2026-01-01.
class Solution:
def oddString(self, words: List[str]) -> str:
def get_diff(word):
return tuple(ord(word[i+1]) - ord(word[i]) for i in range(len(word)-1))
diffs = [get_diff(w) for w in words]
if diffs[0] != diffs[1]:
return words[0] if diffs[1] == diffs[2] else words[1]
for i in range(2, len(words)):
if diffs[i] != diffs[0]:
return words[i]
return ""