leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0522.cpp (736B)
0 class Solution {
1 public:
2 int findLUSlength(vector<string> &strs) const {
3 static const auto LCS = [](const string &a, const string &b) {
4 int i = 0, j = 0;
5 while (i < size(a) && j < size(b)) {
6 if (a[i] == b[j]) i++;
7 j++;
8 }
10 return i == size(a);
11 };
13 sort(begin(strs), end(strs), [](const string &a, const string &b) { return size(a) > size(b); });
15 const int n = size(strs);
16 for (int i = 0; i < n; i++) {
17 for (int j = 0; j < n; j++) {
18 if (i != j && LCS(strs[i], strs[j])) goto next;
19 }
20 return size(strs[i]);
21 next:;
22 }
24 return -1;
25 }
26 };