package
Version:
v0.0.0-...-b071cee
Opens a new window with list of versions in this module.
Published: Aug 9, 2023
License: GPL-3.0
Opens a new window with license information.
Imports: 0
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
面试题 01.09.字符串轮转
1. 题目描述
字符串轮转。给定两个字符串 s1 和 s2 ,请编写代码检查 s2 是否为 s1 旋转而成(比如, waterbottle 是 erbottlewat 旋转后的字符串)。
示例1:
输入:s1 = "waterbottle", s2 = "erbottlewat"
输出:True
示例2:
输入:s1 = "aa", s2 = "aba"
输出:False
提示:
- 字符串长度在[0, 100000]范围内。
说明:
- 你能只调用一次检查子串的方法吗?
标签
字符串 字符串匹配
2. 解题
- 如果二者长度不想等,则直接返回false
- 滑动窗口法,将s2置于s1下方向左滑动,设s2当前对是s1头部对齐的位置是h, 比较s1[0:n-h-1]与s2[h:]是否相等,若相等,再比较s1[n-h:]与s2[0:h]是否相等,若相等,则返回true。否则继续滑动,直至h>=n-1
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.