博客
关于我
leecode 796 旋转字符串
阅读量:346 次
发布时间:2019-03-04

本文共 691 字,大约阅读时间需要 2 分钟。

题目描述

给定两个字符串, 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。

https://leetcode-cn.com/problems/rotate-string/

题解:既然B是A经过若干旋转后得到的,那么A后面拼接A得到的一个新字符串中肯定存在一个子串与B 相同。当然返回true的前提是二者的大小相等。

class Solution {   public:    /**     * 旋转字符串     * @param A string字符串      * @param B string字符串      * @return bool布尔型     */    bool solve(string A, string B) {           // write code here        if(A.size()!=B.size()) return false;        string  C=A.append(A);        if(C.find(B)!=string::npos) return true;        else return false;    }};

转载地址:http://lpse.baihongyu.com/

你可能感兴趣的文章
NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
查看>>
NOAA(美国海洋和大气管理局)气象数据获取与POI点数据获取
查看>>
NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
查看>>
node
查看>>
node exporter完整版
查看>>
node HelloWorld入门篇
查看>>
Node JS: < 一> 初识Node JS
查看>>
Node JS: < 二> Node JS例子解析
查看>>
Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime(93)解决
查看>>
Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime(72)
查看>>
Node 裁切图片的方法
查看>>
node+express+mysql 实现登陆注册
查看>>
Node+Express连接mysql实现增删改查
查看>>
node, nvm, npm,pnpm,以前简单的前端环境为什么越来越复杂
查看>>
Node-RED中Button按钮组件和TextInput文字输入组件的使用
查看>>
vue3+Ts 项目打包时报错 ‘reactive‘is declared but its value is never read.及解决方法
查看>>
Node-RED中Switch开关和Dropdown选择组件的使用
查看>>
Node-RED中使用exec节点实现调用外部exe程序
查看>>
Node-RED中使用function函式节点实现数值计算(相加计算)
查看>>
Node-RED中使用html节点爬取HTML网页资料之爬取Node-RED的最新版本
查看>>