Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3d63977

Browse files
✨feat: Add 796
1 parent dd740b7 commit 3d63977

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

‎Index/模拟.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
| [762. 二进制表示中质数个计算置位](https://leetcode-cn.com/problems/prime-number-of-set-bits-in-binary-representation/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/prime-number-of-set-bits-in-binary-representation/solution/by-ac_oier-w50x/) | 简单 | 🤩🤩🤩🤩 |
8686
| [766. 托普利茨矩阵](https://leetcode-cn.com/problems/toeplitz-matrix/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/toeplitz-matrix/solution/cong-ci-pan-du-qu-cheng-ben-fen-xi-liang-f20w/) | 简单 | 🤩🤩🤩 |
8787
| [794. 有效的井字游戏](https://leetcode-cn.com/problems/valid-tic-tac-toe-state/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/valid-tic-tac-toe-state/solution/gong-shui-san-xie-fen-qing-kuang-tao-lun-pikn/) | 中等 | 🤩🤩🤩🤩 |
88+
| [796. 旋转字符串](https://leetcode-cn.com/problems/rotate-string/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/rotate-string/solution/by-ac_oier-bnkx/) | 简单 | 🤩🤩🤩 |
8889
| [846. 一手顺子](https://leetcode-cn.com/problems/hand-of-straights/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/hand-of-straights/solution/gong-shui-san-xie-shu-ju-jie-gou-mo-ni-t-4hxw/) | 中等 | 🤩🤩🤩 |
8990
| [859. 亲密字符串](https://leetcode-cn.com/problems/buddy-strings/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/buddy-strings/solution/gong-shui-san-xie-jian-dan-zi-fu-chuan-m-q056/) | 简单 | 🤩🤩🤩🤩🤩 |
9091
| [867. 转置矩阵](https://leetcode-cn.com/problems/transpose-matrix/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/transpose-matrix/solution/yi-you-wei-jin-huo-xu-ni-neng-kan-kan-zh-m53m/) | 简单 | 🤩🤩🤩🤩 |
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
### 题目描述
2+
3+
这是 LeetCode 上的 **[796. 旋转字符串](https://leetcode-cn.com/problems/rotate-string/solution/by-ac_oier-bnkx/)** ,难度为 **简单**
4+
5+
Tag : 「模拟」
6+
7+
8+
9+
给定两个字符串,`s``goal`。如果在若干次旋转操作之后,`s` 能变成 `goal`,那么返回 `true`
10+
11+
`s` 的旋转操作就是将 `s` 最左边的字符移动到最右边。
12+
13+
* 例如, 若 `s = 'abcde'`,在旋转一次之后结果就是`'bcdea'`
14+
15+
示例 1:
16+
```
17+
输入: s = "abcde", goal = "cdeab"
18+
19+
输出: true
20+
```
21+
示例 2:
22+
```
23+
输入: s = "abcde", goal = "abced"
24+
25+
输出: false
26+
```
27+
28+
提示:
29+
* 1ドル <= s.length, goal.length <= 100$
30+
* `s``goal` 由小写英文字母组成
31+
32+
---
33+
34+
### 模拟
35+
36+
由于每次旋转操作都是将最左侧字符移动到最右侧,因此如果 `goal` 可由 `s` 经过多步旋转而来,那么 `goal` 必然会出现在 `s + s` 中,即满足 `(s + s).contains(goal)`,同时为了 `s` 本身过长导致的结果成立,我们需要先确保两字符串长度相等。
37+
38+
代码:
39+
```Java
40+
class Solution {
41+
public boolean rotateString(String s, String goal) {
42+
return s.length() == goal.length() && (s + s).contains(goal);
43+
}
44+
}
45+
```
46+
* 时间复杂度:$O(n)$
47+
* 空间复杂度:$O(n)$
48+
49+
---
50+
51+
### 最后
52+
53+
这是我们「刷穿 LeetCode」系列文章的第 `No.796` 篇,系列开始于 2021年01月01日,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完。
54+
55+
在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。
56+
57+
为了方便各位同学能够电脑上进行调试和提交代码,我建立了相关的仓库:https://github.com/SharingSource/LogicStack-LeetCode
58+
59+
在仓库地址里,你可以看到系列文章的题解链接、系列文章的相应代码、LeetCode 原题链接和其他优选题解。
60+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /