commit 3cc200f6afb277734d630bbd8b4b737de68a9e84
parent 3cb52ff34e3dfecfce277a185b2e96c571769e7e
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Tue, 12 Nov 2024 18:14:50 +0100
1 Random Problem
Diffstat:
2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/Problems/0522.cpp b/Problems/0522.cpp
@@ -0,0 +1,27 @@
+class Solution {
+ public:
+ int findLUSlength(vector<string> &strs) const {
+ static const auto LCS = [](const string &a, const string &b) {
+ int i = 0, j = 0;
+ while (i < size(a) && j < size(b)) {
+ if (a[i] == b[j]) i++;
+ j++;
+ }
+
+ return i == size(a);
+ };
+
+ sort(begin(strs), end(strs), [](const string &a, const string &b) { return size(a) > size(b); });
+
+ const int n = size(strs);
+ for (int i = 0; i < n; i++) {
+ for (int j = 0; j < n; j++) {
+ if (i != j && LCS(strs[i], strs[j])) goto next;
+ }
+ return size(strs[i]);
+ next:;
+ }
+
+ return -1;
+ }
+};
diff --git a/README.md b/README.md
@@ -432,6 +432,7 @@ reference and a base for solving problems.
| 0516 | Medium | [Longest Palindromic Subsequence](Problems/0516.cpp) |
| 0518 | Medium | [Coin Change II](Problems/0518.cpp) |
| 0520 | Easy | [Detect Capital](Problems/0520.cpp) |
+| 0522 | Medium | [Longest Uncommon Subsequence II](Problems/0522.cpp) |
| 0523 | Medium | [Continuous Subarray Sum](Problems/0523.cpp) |
| 0524 | Medium | [Longest Word in Dictionary through Deleting](Problems/0524.cpp) |
| 0525 | Medium | [Contiguous Array](Problems/0525.cpp) |