1、题目描述

2.题目分析

字符串操作,注意边界条件即可。

3.代码

  int strStr(string haystack, string needle) {
int n = needle.size();
int res = -;
if( needle.size() == )
return ;
for(string::iterator it = haystack.begin() ; it != haystack.end(); ++it){
if((*it) == needle[]){
bool isEqual = true;
bool isEnd = false;
for(int i = ; i < n; i++){
if( it + i == haystack.end() ){
isEnd = true;
break;
}
if( needle[i] != *(it+i)){
isEqual = false;
break;
}
}
if( isEnd == true )
break;
if( isEqual == true){
res = it-haystack.begin();
break;
} }
}
return res; }

LeetCode题解之 Implement strStr()的更多相关文章

  1. [Leetcode][Python]28: Implement strStr()

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 28: Implement strStr()https://oj.leetco ...

  2. 【一天一道LeetCode】#28. Implement strStr()

    一天一道LeetCode系列 (一)题目 Implement strStr(). Returns the index of the first occurrence of needle in hays ...

  3. 【LeetCode】028. Implement strStr()

    Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...

  4. 【LeetCode】28. Implement strStr() 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 find函数 遍历+切片 日期 题目地址:https ...

  5. 【LeetCode】28 - Implement strStr()

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  6. 【LeetCode】28. Implement strStr() (2 solutions)

    Implement strStr() Implement strStr(). Returns a pointer to the first occurrence of needle in haysta ...

  7. LeetCode OJ:Implement strStr()(实现子字符串查找)

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  8. C# 写 LeetCode easy #28 Implement strStr()

    28.Implement strStr() Implement strStr(). Return the index of the first occurrence of needle in hays ...

  9. 【算法】LeetCode算法题-Implement strStr

    这是悦乐书的第151次更新,第153篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第10题(顺位题号是28).给定两个任意字符串haystack.needle,返回hay ...

随机推荐

  1. puppet的使用:依赖关系整理

    title: date: 2016-05-08 21:45:33 tags: puppet categories: 技术 puppet中的依赖关系整理. 概述 puppet中的依赖关系大概有如下几个: ...

  2. 五:理解控件的运行机制(例:基于Control命名空间的简单控件)

    一:先用最简短的话说点理论的1.asp.net中所有的标准控件都可以重写 2.和控件相关的命名空间有 System.Web.UI.Control是所有控件的基类只提供简单的呈现逻辑,不支持样式表 Sy ...

  3. VS和Eclipse的调试功能哪个更强大?

    以前一直用VS 2012来调试C/C++代码,F5.F10.F11用起来甚是顺手,前面也写过一篇关于VS最好用的快捷键:Visual Studio最好用的快捷键(你最喜欢哪个), 所以对于调试C/C+ ...

  4. WPF实现在电脑重启或关机时执行某些逻辑

    Application类的SessionEnding事件,就是电脑关机或重启时响应的(会话结束事件), 所以只需要在App.xaml中添加SessionEnding <Application x ...

  5. WPF 数据绑定 使用Code First with Database

    一.准备工作 1.开发工具 Visual Studio 2013 2.安装 Entity Framework 6 Tools for Visual Studio 2012 & 2013 来实现 ...

  6. Java设计模式学习记录-代理模式

    代理模式 代理模式是常见设计模式的一种,代理模式的定义是:为其他对象提供一种代理以控制对这个对象的访问. 在某些情况下,一个对象不适合或者不能直接引用另一个对象,而代理对象可以在客户端和目标对象之间起 ...

  7. UVA 11582 Colossal Fibonacci Numbers!(循环节打表+幂取模)

    题目链接:https://cn.vjudge.net/problem/UVA-11582 /* 问题 输入a,b,n(0<a,b<2^64(a and bwill not both be ...

  8. [日常] C语言中的字符数组和字符串

    c语言字符数组和字符串:1.存放字符的数组称为字符数组 char str[]2.'\0'也被称为字符串结束标志3.由" "包围的字符串会自动在末尾添加'\0'4.逐个字符地给数组赋 ...

  9. 通过AOP自定义注解实现日志管理

    前言: 通过自定义注解和AOP结合的方式,实现日志的记录功能 大致流程:项目运行->用户操作调用业务处理类->通过自定义的注解(我理解为一个切点)->进入到AOP切面类(在这里可以获 ...

  10. IDEA中的git更新项目

    1.先pull 2.在add 3. 最后