2451. Odd String Difference Easy

@problem@discussion
#Hash Table#Math#String



1/**
2 * [2451] Odd String Difference
3 *
4 * You are given an array of equal-length strings words. Assume that the length of each string is n.
5 * 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.
6 * 
7 * 	For example, for the string "acb", the difference integer array is [2 - 0, 1 - 2] = [2, -1].
8 * 
9 * All the strings in words have the same difference integer array, except one. You should find that string.
10 * Return the string in words that has different difference integer array.
11 *  
12 * <strong class="example">Example 1:
13 * 
14 * Input: words = ["adc","wzy","abc"]
15 * Output: "abc"
16 * Explanation: 
17 * - The difference integer array of "adc" is [3 - 0, 2 - 3] = [3, -1].
18 * - The difference integer array of "wzy" is [25 - 22, 24 - 25]= [3, -1].
19 * - The difference integer array of "abc" is [1 - 0, 2 - 1] = [1, 1]. 
20 * The odd array out is [1, 1], so we return the corresponding string, "abc".
21 * 
22 * <strong class="example">Example 2:
23 * 
24 * Input: words = ["aaa","bob","ccc","ddd"]
25 * Output: "bob"
26 * Explanation: All the integer arrays are [0, 0] except for "bob", which corresponds to [13, -13].
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	3 <= words.length <= 100
32 * 	n == words[i].length
33 * 	2 <= n <= 20
34 * 	words[i] consists of lowercase English letters.
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/odd-string-difference/
40// discuss: https://leetcode.com/problems/odd-string-difference/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn odd_string(words: Vec<String>) -> String {
46        String::new()
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_2451() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.