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 and B will have length at most 100.
class Solution {
public boolean rotateString(String A, String B) {
if(A == null || B == null || A.length() != B.length()){
return false;
}
if(A.length() == 0 && B.length() == 0){
return true;
} int n = A.length();
     //轮数
for(int i = 0; i< n; i++){
boolean find = true;
       //每一个元素
for(int j = 0; j < n; j++){
int a = A.charAt(j);
int newIndex = (n - i + j) % n;
int b = B.charAt(newIndex);
if(a != b){
find = false;
break;
}
}
if(find){
return true;
}
}
return false;
}
}

LeetCode - Rotate String的更多相关文章

  1. [LeetCode] Rotate String 旋转字符串

    We are given two strings, A and B. A shift on A consists of taking string A and moving the leftmost ...

  2. LeetCode算法题-Rotate String(Java实现)

    这是悦乐书的第317次更新,第338篇原创 在开始今天的算法题前,说几句,今天是世界读书日,推荐两本书给大家,<终身成长>和<禅与摩托车维修艺术>,值得好好阅读和反复阅读. 0 ...

  3. leetcode 344. Reverse String 、541. Reverse String II 、796. Rotate String

    344. Reverse String 最基础的旋转字符串 class Solution { public: void reverseString(vector<char>& s) ...

  4. 796. Rotate String - LeetCode

    Question 796. Rotate String Solution 题目大意:两个字符串匹配 思路:Brute Force Java实现: public boolean rotateString ...

  5. C++ STL@ list 应用 (leetcode: Rotate Array)

    STL中的list就是一双向链表,可高效地进行插入删除元素. List 是 C++标准程式库 中的一个 类 ,可以简单视之为双向 连结串行 ,以线性列的方式管理物件集合.list 的特色是在集合的任何 ...

  6. Rotate String

    Given a string and an offset, rotate string by offset. (rotate from left to right) Example Given &qu ...

  7. Lintcode: Rotate String

    Given a string and an offset, rotate string by offset. (rotate from left to right) Example Given &qu ...

  8. 8. Rotate String

    8. Rotate String Description Given a string and an offset, rotate string by offset. (rotate from lef ...

  9. LeetCode——Reverse String

    LeetCode--Reverse String Question Write a function that takes a string as input and returns the stri ...

随机推荐

  1. Module loader:模块加载器

    <p data-height="265" data-theme-id="0" data-slug-hash="XpqRmq" data ...

  2. U深度U盘启动盘制作教程

    ① 下载u深度u盘启动盘制作工具 ② 一个能够正常使用的u盘(容量大小建议在4g以上) 第一步:安装u深度u盘启动盘制作工具 双击打开已下载好的安装包,点击窗口中立即安装即可: 等待安装完成后,可以点 ...

  3. Python之路-python基础二

    本章内容:      一.编码格式      二.常用数据类型      三.字符串常用方法      四.列表常用方法  五.数据运算      六.课后作业 编码格式:       ASCII A ...

  4. 【资料收集】QT 环境安装配置

    (很详细,极力推荐) [OpenCV] -- win7下配置OpenCV的Qt开发环境 - 代码人生 - 博客频道 - CSDN.NET  http://blog.csdn.net/qiurisuix ...

  5. Python Django 之 静态文件存放设置

    一.静态文件存放路径设置STATICFILES_DIRS 1.在django项目目录下面新建静态文件保存目录 2.在setting中添加相应寻找静态文件目录的配置 STATICFILES_DIRS=( ...

  6. MATLAB 批量处理图片

    function resizephotos(directory, wh, isrecursive, isoverwrite, savetopath, supportFormat) % resizeph ...

  7. Eclipse集成Tomcat插件(特别简单)

    . 只需要一个jar包 复制到eclipse/plugins文件夹下,重启Eclipse即可看到如下三只小猫 1.修改Tomcat (1)Tomcat version:版本 (2)Tomcat Hom ...

  8. C++的string类型和继承C语言风格的字符串的区别与注意事项

    1.尽可能地在C++程序中使用string,不要使用继承而来的C语言风格的字符串,会出现许多安全问题. 2.C语言的字符串风格,是以空字符结束的,在C++的头文件cstring中定义了C语言风格的字符 ...

  9. (C/C++学习笔记) 三. 作用域和可见性

    三. 作用域和可见性 ● 标识符的作用域 标识符的作用域是标识符在程序源代码中的有效范围,从小到大分为函数原型作用域.块作用域(局部作用域),文件作用域(全局作用域). 1. 函数原型作用域 函数原型 ...

  10. Android : 移植curl-7.61.1 及 openssl-1.1.0i

    一.curl-7.61.1 Android平台移植: libcurl是一个免费且易于使用的客户端URL传输库,支持DICT.FILE.FTP.FTPS.Gopher.HTTP.HTTPS.IMAP.I ...