给定两个字符串, A 和 B。

A 的旋转操作就是将 A 最左边的字符移动到最右边。 例如, 若 A = 'abcde',在移动一次之后结果就是'bcdea' 。如果在若干次旋转操作之后,A 能变成B,那么返回True。

示例 1: 输入: A = 'abcde', B = 'cdeab' 输出: true 示例 2: 输入: A = 'abcde', B = 'abced' 输出: false

注意:

  • A 和 B 长度不超过 100。
class Solution {
public:
bool rotateString(string A, string B) {
int len1 = A.size();
int len2 = B.size();
if(len1 != len2)
return false;
A += A;
int idx = A.find(B);
if(idx != string:: npos)
return true;
return false;
}
};

Leetcode796.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. 796. Rotate String旋转字符串

    [抄题]: We are given two strings, A and B. A shift on A consists of taking string A and moving the lef ...

  3. leetcode——Reverse Words in a String 旋转字符串中单词顺序(AC)

    题目例如以下: Given an input string, reverse the string word by word. For example, Given s = "the sky ...

  4. [CareerCup] 1.8 String Rotation 字符串的旋转

    1.8 Assume you have a method isSubstring which checks if one word is a substring of another. Given t ...

  5. 辗转相除法(GCD)求左旋转字符串

    本文写于2017-01-18,从老账号迁移到本账号,原文地址:https://www.cnblogs.com/huangweiyang/p/6297874.html 今天在牛客网上做了一道题,题意就是 ...

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

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

  7. 8. Rotate String

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

  8. 剑指Offer面试题:34.翻转单词顺序VS左旋转字符串

    一.题目一:翻转单词顺序 1.1 题目说明 题目一:输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变.为简单起见,标点符号和普通字母一样处理.例如输入字符串"I am a st ...

  9. 【面试题042】翻转单词顺序VS左旋转字符串

    [面试题042]翻转单词顺序VS左旋转字符串 题目一:     输入一个英文句子,反转句子中单词的顺序,但单词内字符的顺序不变.为简单起见,标点符号和普通字母一样处理.     例如输入字符串“I a ...

随机推荐

  1. 90 k数和 II

    原题网址:https://www.lintcode.com/problem/k-sum-ii/description 描述 Given n unique integers, number k (1&l ...

  2. Ceisum官方教程2 -- 项目实例(workshop)

    原文地址:https://cesiumjs.org/tutorials/Cesium-Workshop/ 概述 我们很高兴欢迎你加入Cesium社区!为了让你能基于Cesium开发自己的3d 地图项目 ...

  3. gulp入门之常见处理方式(三)

    整合 streams 来处理错误 默认情况下,在 stream 中发生一个错误的话,它会被直接抛出,除非已经有一个时间监听器监听着 error时间. 这在处理一个比较长的管道操作的时候会显得比较棘手. ...

  4. CF538G (套路题)

    CF538G 题目大意 你有一个长度为\(l\)的指令序列,每个指令为向上,向下,向左,向右中的一种. 机器人会循环执行该序列,即,执行完第\(l\)个指令后,就会重新开始执行第一个指令. 现在,给你 ...

  5. phonegap geolocation android 问题

    很纠结的 phonegap 使用定位的时候 android 获取地址异常的慢,为什么呢? 经过分析 如果android 只开启gprs 上网功能 可以立即获取到经纬度 如果只开启wifi 根本就获取不 ...

  6. MySQL系列(十)--用户权限及远程访问

    本文基于MySQL8.0,记录一下完整的远程访问的过程,以及这个过程中可能遇到的问题,MySQL运行在阿里云服务器,操作系统:CentOS 7.6 64位 顺便说下,买服务器还是要双十二这种拉新活动再 ...

  7. leetcode 492-543 easy

    492. Construct the Rectangle Input: 4 Output: [2, 2] Explanation: The target area is 4, and all the ...

  8. TZ_13_Eureka的高可用

    1.Eureka Server即服务的注册中心,在刚才上一篇中,我们只有一个EurekaServer,事实上EurekaServer也可以是一个集群,形成高可用的Eureka中心. 目的:多个Eure ...

  9. iview 小问题笔记

    总结一下用 iview 组件期间遇到的小问题.一边做项目一边做笔记. 官方文档:iview API 按需引入: 1,iview 分页组件 <Page :total="aboutPage ...

  10. shell mysql数据迁移/备份

    保存为.sh文件,配置运行即可 #!/bin/bash #### change the values below where needed..... #### 多数据库DBNAMES="My ...