goden0109

package
v0.0.0-...-b071cee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 0 Imported by: 0

README

面试题 01.09.字符串轮转

1. 题目描述

字符串轮转。给定两个字符串 s1s2 ,请编写代码检查 s2 是否为 s1 旋转而成(比如, waterbottleerbottlewat 旋转后的字符串)。

示例1:

 输入:s1 = "waterbottle", s2 = "erbottlewat"
 输出:True

示例2:

 输入:s1 = "aa", s2 = "aba"
 输出:False

提示:

  • 字符串长度在[0, 100000]范围内。 说明:
  • 你能只调用一次检查子串的方法吗?

标签 字符串 字符串匹配

2. 解题

  1. 如果二者长度不想等,则直接返回false
  2. 滑动窗口法,将s2置于s1下方向左滑动,设s2当前对是s1头部对齐的位置是h, 比较s1[0:n-h-1]与s2[h:]是否相等,若相等,再比较s1[n-h:]与s2[0:h]是否相等,若相等,则返回true。否则继续滑动,直至h>=n-1

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL