Implement strStr().

Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.

Summary: be careful about the corner case, haystack = "", needle = ""

     char *strStr(char *haystack, char *needle) {
if(haystack[] == '\0' && needle[] == '\0')
return haystack; int hay_idx = ;
while(haystack[hay_idx] != '\0'){
bool find = true;
int tmp_idx = hay_idx;
int needle_idx = ;
while(needle[needle_idx] != '\0'){
if(haystack[tmp_idx] == '\0')
return NULL;
if(haystack[tmp_idx] != needle[needle_idx]){
find = false;
break;
}
tmp_idx ++;
needle_idx ++;
}
if(find)
return haystack + hay_idx;
else
hay_idx ++; }
return NULL;
}

Implement strStr() [LeetCode]的更多相关文章

  1. Implement strStr() leetcode java

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

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

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

  3. [Leetcode] implement strStr() (C++)

    Github leetcode 我的解题仓库   https://github.com/interviewcoder/leetcode 题目: Implement strStr(). Returns ...

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

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

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

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

  6. LeetCode专题-Python实现之第28题: Implement strStr()

    导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...

  7. LeetCode(28)题解:Implement strStr()

    https://leetcode.com/problems/implement-strstr/ 题目: Implement strStr(). Returns the index of the fir ...

  8. LeetCode Implement strStr()(Sunday算法)

    LeetCode解题之Implement strStr() 原题 实现字符串子串匹配函数strStr(). 假设字符串A是字符串B的子串.则返回A在B中首次出现的地址.否则返回-1. 注意点: - 空 ...

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

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

随机推荐

  1. synchronized同步块和volatile同步变量

    Java语言包含两种内在的同步机制:同步块(或方法)和 volatile 变量.这两种机制的提出都是为了实现代码线程的安全性.其中 Volatile 变量的同步性较差(但有时它更简单并且开销更低),而 ...

  2. Aggregate

    对序列应用累加器函数. /// <summary> /// 计算校验和,SUM /// </summary> public byte CalculateCheckSum(byt ...

  3. RDIFramework.NET 框架兼容各种数据库类型事务使用范例参考

    RDIFramework.NET 框架兼容各种数据库类型事务使用范例参考 RDIFramwork.NET框架对数据库的事务做了很好的控制,对多表或多条语句需要在同一事务执行提供了很好的支持,同时支持任 ...

  4. 应该具备的调试技能(java)

    ------Java部分---------- 1. tomcat在eclispe中怎样启动调试模式2. 带有main方法的Java应用程序怎样启动调试模式3. 调试在eclispe中的快捷键 F5 F ...

  5. 20145320 《Java程序设计》第6周学习总结

    20145320 <Java程序设计>第6周学习总结 教材学习内容总结 第十章 输入/输出 流(Stream)是对「输入输出」的抽象,注意「输入输出」是相对程序而言的 10.1 Input ...

  6. vue.js慢速入门(2)

    4.组件使用基础 什么是组件?组件可以理解为可重用的自定义HTML. 可以使用一堆组件来构造大型应用,任意类型的应用界面都可以抽象为一个组件树: 可以把组件代码按照template.style.scr ...

  7. :enabled 匹配所有可用元素

    描述: 查找所有可用的input元素 HTML 代码: <form> <input name="email" disabled="disabled&qu ...

  8. Linux top和负载的说明

    转自:http://bbs.linuxtone.org/thread-1684-1-1.html top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windo ...

  9. sql server中如何查看执行效率不高的语句

    sql server中,如果想知道有哪些语句是执行效率不高的,应该如何查看呢?下面就将为您介绍sql server中如何查看执行效率不高的语句,供您参考.   在测量功能时,先以下命令清除sql se ...

  10. illustrator将图片转换成ai路径

    窗口->图像描摹 第一选择模式:彩色 第二步:调整颜色的数值 最后点击工具栏上的扩展按钮转成路径 搞定~