[LeetCode] 796. Rotate String_Easy **KMP
We are given two strings, A and B.
A shift on A consists of taking string A and moving the leftmost character to the rightmost position. For example, if A = 'abcde', then it will be 'bcdea' after one shift on A. Return True if and only if A can become B after some number of shifts on A.
Example 1:
Input: A = 'abcde', B = 'cdeab'
Output: true Example 2:
Input: A = 'abcde', B = 'abced'
Output: false
Note:
AandBwill have length at most100.
这个题目比较有技巧,因为直接判断B 是否in A + A即可。不过要注意进行length的判断。 O(n^2)
**Improve: KMP(有待提升)
Code
class Solution:
def rotateString(self, A, B):
return len(A) == len(B) and A in B + B
[LeetCode] 796. Rotate String_Easy **KMP的更多相关文章
- leetcode 344. Reverse String 、541. Reverse String II 、796. Rotate String
344. Reverse String 最基础的旋转字符串 class Solution { public: void reverseString(vector<char>& s) ...
- 796. Rotate String - LeetCode
Question 796. Rotate String Solution 题目大意:两个字符串匹配 思路:Brute Force Java实现: public boolean rotateString ...
- [array] leetcode - 48. Rotate Image - Medium
leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...
- [LeetCode] 61. Rotate List 旋转链表
Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: I ...
- 【Leetcode_easy】796. Rotate String
problem 796. Rotate String solution1: class Solution { public: bool rotateString(string A, string B) ...
- 【LeetCode】796. Rotate String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- [LeetCode&Python] Problem 796. Rotate String
We are given two strings, A and B. A shift on A consists of taking string A and moving the leftmost ...
- [Leetcode][048] Rotate Image 略详细 (Java)
题目在这里 https://leetcode.com/problems/rotate-image/ [个人分析] 这个题目,我觉得就是考察基本功.考察细心的,算法方面没有太多东西,但是对于坐标的使用有 ...
- LeetCode 189. Rotate Array (旋转数组)
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...
随机推荐
- sql server性能查询,连接数
1)使用以下查询语句: select * from sysprocesses where dbid in (select dbid from sysdatabases where name='My ...
- 【大数据系列】MapReduce示例好友推荐
package org.slp; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import ...
- Maven —— scope 元素的值及其含义
1.compile 缺省值,所属依赖在所有的classpath中可用,同时它们也会被打包(随着项目一起发布). 2.provided 只有当JDK或者某个容器已提供该依赖之后才使用.如servlet. ...
- dpkg安装deb缺少依赖包的解决方法
[先贴出解决方案(基于Ubuntu)]: 使用dpkg -i *.deb 的时候出现依赖没有安装 使用apt-get -f -y install 解决依赖问题后再执行dpkg安装deb包 === ...
- Docker制作私有的基础镜像
debootstrap是debian/ubuntu下的一个工具,用来构建一套基本的系统(根文件系统).生成的目录符合Linux文件系统标准(FHS),即包含了/boot./etc./bin./usr等 ...
- 【转】C内存管理
在任何程序设计环境及语言中,内存管理都十分重要.在目前的计算机系统或嵌入式系统中,内存资源仍然是有限的.因此在程序设计中,有效地管理内存资源是程序员首先考虑的问题. 第1节主要介绍内存管理基本概念,重 ...
- kvm虚拟机的重命名
1.查看所有的kvm虚拟机 [root@5201351_kvm ~]# virsh list --all 2.重命名kvm虚拟机最好是将虚拟机先关机,然后再导出其xml文件 [root@5201351 ...
- Node.js 文件系统fs模块
Node.js 文件系统封装在 fs 模块是中,它提供了文件的读取.写入.更名.删除.遍历目录.链接等POSIX 文件系统操作. 与其他模块不同的是,fs 模块中所有的操作都提供了异步的和 同步的两个 ...
- 美团开源 SQL 优化工具 SQLAdvisor
https://www.oschina.net/news/82725/sqladvisor-opensource https://github.com/Meituan-Dianping/SQLAdvi ...
- iOS - 视频播放处理全屏/横屏时候遇见的坑
视频播放想要全屏,使用shouldAutorotate方法禁止主界面,tabbar控制器横屏,导致push进入播放页面不能横屏的问题... - (BOOL)shouldAutorotate { ret ...