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. day29 socketsever ftp功能简单讲解

    今日所学 一.ftp上传简单实例 二.socketsever的固定用法 三.验证合法性连接 1.ftp上传实例 这个题目是我们现在网络编程比较基础一点的题目 下面我们只写简单上传的代码 上传服务端的代 ...

  2. 非图片格式如何转成lmdb格式--caffe

    链接 LMDB is the database of choice when using Caffe with large datasets. This is a tutorial of how to ...

  3. 简单选择排序(Simple Selection Sort)

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  4. const & define & inline

    0x01  const & define区别 宏定义#define发生在预编译期,而const,enum定义的常量发生在编译期,两者的重要差别在于编译期里的变量是进符号表的,而预编译期的宏是简 ...

  5. Centos7搭建软路由

    Xenserver环境: 一:环境准备 内网:192.168.2.100 外网:x.x.x.x 1.1:登陆XenCenter 1.2:进入Xenserver中的Networking选项 1.3:点选 ...

  6. Positioning

      boxPostion.html <html><head> <title>Box Position</title><meta charset=& ...

  7. win10下安装scala流程及问题

    第一步:Java 设置 检测方法前文已说明,这里不再描述. 如果还为安装,可以参考我们的Java 开发环境配置. 接下来,我们可以从 Scala 官网地址 http://www.scala-lang. ...

  8. selenium 自动化安装火狐谷歌插件

    谷歌插件下载地址 https://npm.taobao.org/mirrors/chromedriver selenium下载地址 https://pypi.org/simple/selenium/ ...

  9. CountDownLatch & CyclicBarrier

    CountDownLatch 在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待.用给它的代数初始化CountDownLatch,且计数器无法被重置.当前计数到达0之前,await方 ...

  10. Coach Said No Worry

    I have been losing memories those days. I can't get through what I was doing right then. I have prom ...