[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:
A
andB
will 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 ...
随机推荐
- EGL 1.0 学习笔记
http://hi.baidu.com/leo_xxx/item/b01b1fc29abff355ac00ef5c 基本概念 EGL是OpenGL ES与本地Window系统之间的桥梁.EGL创建渲染 ...
- Centos重新启动网络配置文件,/etc/resolv.conf被覆盖或清空问题解决
Centos在执行命令 yum update时报错如下: Could not get metalink https://mirrors.fedoraproject.org/metalink?repo= ...
- POJ 1117 Pairs of Integers
Pairs of Integers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4133 Accepted: 1062 Des ...
- Windows Server 2012设置WinDbg Kernel Debugging Local
网上主要提到了以下两点: 1.cmd窗口输入bcdedit /debug on,重新启动计算机. 2.下载对应版本Windows符号文件,并添加环境变量_NT_SYMBOL_PATH. 其实根据环境不 ...
- 23种设计模式之代理模式(Proxy)
代理模式是一种对象结构型模式,可为某个对象提供一个代理,并由代理对象控制对原对象的引用.代理模式能够协调调用者和被调用者,能够在一定程度上降低系统的耦合度,其缺点是请求的处理速度会变慢,并且实现代理模 ...
- iOS - 引用计数探讨
<Objective-C 高级编程> 这本书有三个章节,我针对每一章节进行总结并加上适当的扩展分享给大家.可以从下面这张图来看一下这三篇的整体结构: 注意,这个结构并不和书中的结构一致,而 ...
- Python之时间模块
1,怎么打印时间戳 2,怎么打印日期 3,怎么把字符串转换成python认识的日期 把日期转换成字符串 字符串转换成日期格式 time.strptime("2017-5-16",& ...
- ICSharpCode.SharpZipLib.dll 压缩多文件
网站:http://icsharpcode.github.io/SharpZipLib/ 引用:ICSharpCode.SharpZipLib.dll private string CompassZi ...
- CCCC训练赛一些模板 struct sstream
重载与构造 struct node { friend bool operator< (node n1, node n2) { return n1.priority > n2.priorit ...
- AOP 详解
1. 需求:统计方法执行的性能情况(来源:<精通Spring 4.x>) // 性能监视类 PerformanceMonitor package com.noodles.proxy; pu ...