判断A是不是B的旋转字符串的3种方法
来源:互联网 发布:最完美网络架构图 编辑:程序博客网 时间:2024/05/22 05:02
class Rotation {public: bool chkRotation(string A, int lena, string B, int lenb) { // write code here if(lena != lenb) return true; string C; C = A + A; if(C.find(B,0) != -1) return true; return false; }};
class Rotation {public: bool chkRotation(string A, int lena, string B, int lenb) { // write code here if(lena != lenb) return false; string C = A + A; for(int i = 0; i < lena + lena;i++){ if(C.substr(i,lenb) == B) return true; } return false; }}
kmp匹配
class Rotation {public: bool chkRotation(string A, int lena, string B, int lenb) { // write code here if(lena != lenb) return false; string C = A + A; int next[lenb];// int *next = new int[lenb]; return kmp(C,B,next); } void makeNext(string B,int next[]){ next[0] = 0; int k = 0; for(unsigned int i = 1; i < B.size();i++){ while(k > 0 && B[i] != B[k]) k = next[k -1]; if(B[i] == B[k]) ++k; next[i] = k; } } bool kmp(string C,string B,int next[]){ makeNext(B,next); unsigned int lengthOfCompare = 0; for(unsigned int i = 0; i < C.size(); ++i){ while(lengthOfCompare > 0 && C[i] != B[lengthOfCompare]) lengthOfCompare = next[lengthOfCompare - 1]; if(B[lengthOfCompare] == C[i]) ++lengthOfCompare; if(lengthOfCompare == B.size()) return true; } return false; }};
0 0
- 判断A是不是B的旋转字符串的3种方法
- startsWith(),endsWith()的作用,用法,判断字符串a 是不是以字符串b开头或结尾
- startsWith(),endsWith()的作用,用法,判断字符串a 是不是以字符串b开头或结尾
- startsWith(),endsWith()的作用,用法,判断字符串a 是不是以字符串b开头或结尾
- startsWith(),endsWith()的作用,用法,判断字符串a 是不是以字符串b开头或结尾
- 判断字符串是不是数字的方法
- 95 1.判断一字符串是不是对称 2.用递归的方法判断整数组 a[N]是不是升序排列
- 判断字符串是不是数字的三种方法
- 判断字符串是不是回文的两种方法
- 判断二叉树B是不是二叉树A的子树
- 剑指offer-判断B是不是A的子结构
- 判断树 B 是不是 树 A 的子树
- 输入两颗二叉树A,B,判断B是不是A的子结构。
- java实现:输入两颗二叉树A,B,判断B是不是A的子结构
- 输入两颗二叉树A,B,判断B是不是A的子结构
- 输入两颗二叉树A和B,判断B是不是A的子结构
- java 输入两颗二叉树A,B,判断B是不是A的子结构。
- 输入两颗二叉树A,B,判断B是不是A的子结构
- 介绍bigpipe以及在django上的实现,bigpipedjango实现
- JavaScript 进阶学习 5 内置对象
- 解决UnicodeEncodeError: 'ascii' codec can't encode characters in position问题
- 【学习笔记】3D图形核心基础精炼版-12:stage3D实战-动态阴影 shadow mapping 和范例工程4
- Android 4.0 Launcher源码分析系列(三)
- 判断A是不是B的旋转字符串的3种方法
- 百度地图通过经纬度获取地址信息
- web性能优化小结
- asp.net mvc 用Redis实现分布式集群共享Session
- Trie的java实现
- 结构体定义:struct与typedef struct 用法详解和用法小结
- 【转】 cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
- 磊科路由器动态获取IP模式下不显示DNS设置的问题
- 简单地C#导出word(三)