-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2451.差值数组不同的字符串.cpp
executable file
·72 lines (66 loc) · 1.46 KB
/
2451.差值数组不同的字符串.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* @lc app=leetcode.cn id=2451 lang=cpp
* @lcpr version=21908
*
* [2451] 差值数组不同的字符串
*/
using namespace std;
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// @lc code=start
class Solution {
public:
string oddString(vector<string>& words) {
int ans;
for(int pos=1;pos<words[0].length();pos++)
{
vector<int> diff;
unordered_map<int,int> dict;
int stdnum;
for(int i=0;i<words.size();i++)
{
int tdiff=int(words[i][pos])-int(words[i][pos-1]);
if(dict.find(tdiff)==dict.end())
{
dict[tdiff]=0;
}
dict[tdiff]++;
diff.push_back(tdiff);
}
for(auto it:dict)
{
if(it.second>1)stdnum=it.first;
}
for(int i=0;i<diff.size();i++)
{
if(diff[i]!=stdnum)
{
ans=i;
}
}
}
return words[ans];
}
};
// @lc code=end
/*
// @lcpr case=start
// ["adc","wzy","abc"]\n
// @lcpr case=end
// @lcpr case=start
// ["aaa","bob","ccc","ddd"]\n
// @lcpr case=end
*/