Skip to content

Commit aba138e

Browse files
committed
✨feat: Add 521
1 parent 13ec7cb commit aba138e

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

Index/模拟.md

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
| [506. 相对名次](https://leetcode-cn.com/problems/relative-ranks/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/relative-ranks/solution/gong-shui-san-xie-jian-dan-pai-xu-mo-ni-cmuzj/) | 简单 | 🤩🤩🤩🤩 |
5858
| [507. 完美数](https://leetcode-cn.com/problems/perfect-number/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/perfect-number/solution/gong-shui-san-xie-jian-dan-mo-ni-tong-ji-e6jk/) | 简单 | 🤩🤩🤩 |
5959
| [520. 检测大写字母](https://leetcode-cn.com/problems/detect-capital/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/detect-capital/solution/gong-shui-san-xie-jian-dan-zi-fu-chuan-m-rpor/) | 简单 | 🤩🤩🤩🤩 |
60+
| [521. 最长特殊序列 Ⅰ](https://leetcode-cn.com/problems/longest-uncommon-subsequence-i/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/longest-uncommon-subsequence-i/solution/gong-shui-san-xie-nao-jin-ji-zhuan-wan-z-nj3w/) | 简单 | 🤩🤩🤩🤩 |
6061
| [528. 按权重随机选择](https://leetcode-cn.com/problems/random-pick-with-weight/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/random-pick-with-weight/solution/gong-shui-san-xie-yi-ti-shuang-jie-qian-8bx50/) | 中等 | 🤩🤩🤩🤩 |
6162
| [537. 复数乘法](https://leetcode-cn.com/problems/complex-number-multiplication/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/complex-number-multiplication/solution/gong-shui-san-xie-jian-dan-mo-ni-ti-by-a-avlh/) | 中等 | 🤩🤩🤩🤩 |
6263
| [539. 最小时间差](https://leetcode-cn.com/problems/minimum-time-difference/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/minimum-time-difference/solution/gong-shui-san-xie-jian-dan-mo-ni-ti-by-a-eygg/) | 中等 | 🤩🤩🤩🤩 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
### 题目描述
2+
3+
这是 LeetCode 上的 **[521. 最长特殊序列 Ⅰ](https://leetcode-cn.com/problems/longest-uncommon-subsequence-i/solution/gong-shui-san-xie-nao-jin-ji-zhuan-wan-z-nj3w/)** ,难度为 **简单**
4+
5+
Tag : 「脑筋急转弯」
6+
7+
8+
9+
给你两个字符串 `a` 和 `b`,请返回 这两个字符串中 最长的特殊序列  。如果不存在,则返回 $-1$ 。
10+
11+
「最长特殊序列」 定义如下:该序列为 某字符串独有的最长子序列(即不能是其他字符串的子序列) 。
12+
13+
字符串 `s` 的子序列是在从 `s` 中删除任意数量的字符后可以获得的字符串。
14+
15+
例如,`“abc”` 是 `“aebdc”` 的子序列,因为您可以删除 `“aebdc”` 中的下划线字符来得到 `“abc”``“aebdc”` 的子序列还包括 `“aebdc”``“aeb”``“”` (空字符串)。
16+
17+
示例 1:
18+
```
19+
输入: a = "aba", b = "cdc"
20+
21+
输出: 3
22+
23+
解释: 最长特殊序列可为 "aba" (或 "cdc"),两者均为自身的子序列且不是对方的子序列。
24+
```
25+
示例 2:
26+
```
27+
输入:a = "aaa", b = "bbb"
28+
29+
输出:3
30+
31+
解释: 最长特殊序列是“aaa”和“bbb”。
32+
```
33+
示例 3:
34+
```
35+
输入:a = "aaa", b = "aaa"
36+
37+
输出:-1
38+
39+
解释: 字符串a的每个子序列也是字符串b的每个子序列。同样,字符串b的每个子序列也是字符串a的子序列。
40+
```
41+
42+
提示:
43+
* $1 <= a.length, b.length <= 100$
44+
* `a` 和 `b` 由小写英文字母组成
45+
46+
---
47+
48+
### 脑筋急转弯
49+
50+
当两字符串不同时,我们总能选择长度不是最小的字符串作为答案,而当两字符串相同时,我们无法找到特殊序列。
51+
52+
代码:
53+
```Java
54+
class Solution {
55+
public int findLUSlength(String a, String b) {
56+
return a.equals(b) ? -1 : Math.max(a.length(), b.length());
57+
}
58+
}
59+
```
60+
* 时间复杂度:字符串比较复杂度与长度成正比,复杂度为 $O(\max(n, m))$
61+
* 空间复杂度:$O(1)$
62+
63+
---
64+
65+
### 最后
66+
67+
这是我们「刷穿 LeetCode」系列文章的第 `No.521` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完。
68+
69+
在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。
70+
71+
为了方便各位同学能够电脑上进行调试和提交代码,我建立了相关的仓库:https://github.com/SharingSource/LogicStack-LeetCode
72+
73+
在仓库地址里,你可以看到系列文章的题解链接、系列文章的相应代码、LeetCode 原题链接和其他优选题解。
74+

0 commit comments

Comments
 (0)