2451. Odd String Difference
Description
You are given an array of equal-length strings words. Assume that the length of each string is n.
Each string words[i] can be converted into a difference integer array difference[i] of length n - 1 where difference[i][j] = words[i][j+1] - words[i][j] where 0 <= j <= n - 2. Note that the difference between two letters is the difference between their positions in the alphabet i.e.the position of 'a' is 0, 'b' is 1, and 'z' is 25.
- For example, for the string
"acb", the difference integer array is[2 - 0, 1 - 2] = [2, -1].
All the strings in words have the same difference integer array, except one . You should find that string.
Return the string in words that has different difference integer array .
Example 1:
1 | Input: words = ["adc","wzy","abc"] |
Example 2:
1 | Input: words = ["aaa","bob","ccc","ddd"] |
Constraints:
3 <= words.length <= 100n == words[i].length2 <= n <= 20words[i]consists of lowercase English letters.
Hints/Notes
- 2025/03/13 Q3
- string
- No solution from 0x3F or Leetcode
Solution
Language: C++
1 | class Solution { |