class Solution {
public:
int strStr(string haystack, string needle) {
if(needle.empty())return ; //needle empty
if(haystack.empty()) return -; //haystack empty
for(int i = , j = ; i+j < haystack.size();) {
if(haystack[i+j] != needle[j])i++, j = ; //no equal needle index to 0, haystack index move to next.
else j++; //equal both move to next
if(j == needle.size())return i; //thr first time find substr.
}
return -;
}
};

Leetcode028. Implement strStr()的更多相关文章

  1. [LeetCode] Implement strStr() 实现strStr()函数

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

  2. 28. Implement strStr()

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

  3. Leetcode 详解(Implement strstr)

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

  4. [leetcode 27]Implement strStr()

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

  5. Leetcode #28. Implement strStr()

    Brute Force算法,时间复杂度 O(mn) def strStr(haystack, needle): m = len(haystack) n = len(needle) if n == 0: ...

  6. 【leetcode】Implement strStr() (easy)

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

  7. [LeetCode] Implement strStr()

    Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...

  8. Implement strStr()

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

  9. Implement strStr() [LeetCode]

    Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...

随机推荐

  1. hbase读写流程

    一. Hbase读流程 META表记录着表的原信息,根据rowkey查询META表,获取所在region信息 客户端去相应的regionServer查询数据,先查询memStore(memstore是 ...

  2. PLSQL_闪回操作4_Flashback Drop

    2014-06-25 Created By BaoXinjian

  3. NeHe OpenGL教程 第二十五课:变形

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  4. dede的幻灯片除了首页其他页面也显示的方法,

    <script language='javascript'> linkarr = new Array(); picarr = new Array(); textarr = new Arra ...

  5. Laravel5.0 CSRFチェックを無効化(修改后可以像5.1以上那样从CSRF保护中排除指定URL)

    Laravel5では全てのPOSTに勝手にCSRFチェックが付いてきます.便利と言えば便利ですが.Laravel外からのPOSTを受け取りたいときなど大迷惑です. CSRFチェックを排除する方法が何故 ...

  6. ethereal抓包工具

    ethereal是目前网络上开源的一款功能强大的以太网抓包工具,该软件可以监听异常封包,检测软件封包问题,从网络上抓包,并且能对数据包进行分析,从而帮助用户解决各种网络故障,更加方便查看.监控TCP ...

  7. dom4j-full.jar 解析 XML

    dom4j-full.jar 解析 XML public Document getDocument() throws DocumentException { SAXReader read=new SA ...

  8. dedecms列表页如何让文章列表里面的文章每隔五篇就隔开一段空间

    dedecms列表页如何让文章列表里面的文章每隔五篇就隔开一段空间,运用js控制列表样式的方法. 代码如下: <script type="text/javascript"&g ...

  9. Oracle中的单行函数

    Oracle中的单行函数 1 字符函数 UPPER()--将字符串转换为大写 SELECT UPPER('abc') FROM dual; LOWER()-将字符串转换为小写 SELECT LOWER ...

  10. bootstrap与jqueryui按钮冲突的解决

    bootstrap与jqueryui按钮冲突的解决 (2013-10-15 14:09:36)转载▼ 标签: 情感 分类: jQuery 参考: http://getbootstrap.com/jav ...