28. Implement strStr()【easy】
28. Implement strStr()【easy】
Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
解法一:
class Solution {
public:
int strStr(string haystack, string needle) {
if (haystack.empty() && needle.empty()) {
return ;
} if (haystack.empty()) {
return -;
} if (haystack.size() < needle.size()) {
return -;
} for (string::size_type i = ; i < haystack.size() - needle.size() + ; i++) {
string::size_type j = ;
for (j = ; j < needle.size(); j++) {
if (haystack[i + j] != needle[j]) {
break;
}
} if (j == needle.size()) {
return i;
}
} return -;
}
};
28. Implement strStr()【easy】的更多相关文章
- 28.Implement strStr()【leetcod】
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- 495. Implement Stack【easy】
Implement a stack. You can use any data structure inside a stack except stack itself to implement it ...
- c语言 Implement strStr()【Leetcode】
实现在一个母字符串中找到第一个子字符串的位置. #include <stdio.h> #include <string.h> #define _IRON_TRUE 1 #def ...
- 28. Search a 2D Matrix 【easy】
28. Search a 2D Matrix [easy] Write an efficient algorithm that searches for a value in an mx n matr ...
- 170. Two Sum III - Data structure design【easy】
170. Two Sum III - Data structure design[easy] Design and implement a TwoSum class. It should suppor ...
- 206. Reverse Linked List【easy】
206. Reverse Linked List[easy] Reverse a singly linked list. Hint: A linked list can be reversed eit ...
- 83. Remove Duplicates from Sorted List【easy】
83. Remove Duplicates from Sorted List[easy] Given a sorted linked list, delete all duplicates such ...
- 141. Sqrt(x) 【easy】
141. Sqrt(x) [easy] Implement int sqrt(int x). Compute and return the square root of x. Example sqrt ...
- leetCode练题——28. Implement strStr()
1.题目 28. Implement strStr()——Easy Implement strStr(). Return the index of the first occurrence of ne ...
随机推荐
- 【分块】【哈希】bzoj3578 GTY的人类基因组计划2
每个房间用一个集合来维护,具体来说,就是给1-n的数每个数一个long long的hash值,往集合S里insert(i),就是S^=HASH[i]:erase(i),也是S^=HASH[i]. 用m ...
- 使用ASP.Net WebAPI构建REST服务(七)——调试工具
由于WebAPI本身是基于HTTP协议的,在开发过程中,我们可以使用浏览器或Fiddler等HTTP工具辅助开发.与此同时,微软也提供了一些工具方便我们调试,使得开发更加简单快捷,本文就简单的介绍一下 ...
- 【SQL Server学习笔记】事务、锁定、阻塞、死锁 sys.sysprocesses
http://blog.csdn.net/sqlserverdiscovery/article/details/7712068 Column name Data type Description ...
- Oracle API Gateway SOAP到REST协议转换
1.SOAP到REST协议转换 打开policystudio,加入一个policy Container. 搜索extract rest 设置成为start 搜索set message,将url中的变量 ...
- mac上虚拟机:VMWare Fusion, VirtualBox, Parallels Desktop, CrossOver, Veertu
作者:Louis Tong链接:https://www.zhihu.com/question/35731328/answer/66127970来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非 ...
- [转载]DIY树莓派之随身工具箱
摆弄树莓派有一年多了,在这里把经验分享给大家,少走弯路. 先放图两张. 搭建目的: wifi信号中转站\网站服务器\IC卡渗透测试\中间人\otr… 基于树莓派3 系统为Kali Linux 2017 ...
- CentOS6.6下DRBD+HeartBeat+NFS配置
一.DRBD配置 Distributed Replicated Block Device(DRBD)是一个用软件实现的.无共享的.服务器之间镜像块设备内容的存储复制解决方案. 我们可以理解为它其实就是 ...
- 深度剖析OpenGL ES中的多线程和多窗口渲染技术
由 创新网小编 于 星期五, 2014-04-11 14:56 发表 移动设备中的CPU和GPU已经变得很强大,到处都是配备一个或多个高分辨率屏幕的设备,需要使用带有图形驱动器的复杂交互也日益增加.在 ...
- 如何在Ubuntu上使用Glances监控系统
导读 Glances 是一个用于监控系统的跨平台.基于文本模式的命令行工具.它是用 Python 编写的,使用 psutil 库从系统获取信息.你可以用它来监控 CPU.平均负载.内存.网络接口.磁盘 ...
- nginx+vue实例纪录
参考:http://www.cnblogs.com/wuac/p/6406843.html 新建工作目录vuepro,命令行之行命令:vue init webpack vue-test (项目默认的名 ...