Implement strStr() [LeetCode]
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]的更多相关文章
- Implement strStr() leetcode java
		题目: Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if ... 
- [LeetCode] Implement strStr() 实现strStr()函数
		Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ... 
- [Leetcode] implement strStr() (C++)
		Github leetcode 我的解题仓库 https://github.com/interviewcoder/leetcode 题目: Implement strStr(). Returns ... 
- [Leetcode][Python]28: Implement strStr()
		# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 28: Implement strStr()https://oj.leetco ... 
- 【一天一道LeetCode】#28. Implement strStr()
		一天一道LeetCode系列 (一)题目 Implement strStr(). Returns the index of the first occurrence of needle in hays ... 
- LeetCode专题-Python实现之第28题: Implement strStr()
		导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ... 
- LeetCode(28)题解:Implement strStr()
		https://leetcode.com/problems/implement-strstr/ 题目: Implement strStr(). Returns the index of the fir ... 
- LeetCode Implement strStr()(Sunday算法)
		LeetCode解题之Implement strStr() 原题 实现字符串子串匹配函数strStr(). 假设字符串A是字符串B的子串.则返回A在B中首次出现的地址.否则返回-1. 注意点: - 空 ... 
- [LeetCode] 28. Implement strStr() 实现strStr()函数
		Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ... 
随机推荐
- swprintf %s %ws %S 的区别
			http://www.codeproject.com/Articles/20869/D-Fast-Wavelet-Transform-Library-for-Image-Proces该作者提供的源代码 ... 
- JSONP使用笔记
			JSONP JSONP是实现跨域GET请求的一种方法, 原理上利用script标签可以动态加载JS文件, 将不同源站点的JSON数据加载到本网站来,如果给定回调函数,将回调函数名传递到服务器端, 在服 ... 
- spring MVC配置详解
			现在主流的Web MVC框架除了Struts这个主力 外,其次就是Spring MVC了,因此这也是作为一名程序员需要掌握的主流框架,框架选择多了,应对多变的需求和业务时,可实行的方案自然就多了.不过 ... 
- Unity 对象查找
			GameObject.Find() 对象名 可查找带不带脚本,不能查隐藏,有可能不是要找的对象 GameObject.Find() 目录结构 可查找带不带脚本,能查隐藏,能确定是要找的对象 trans ... 
- (九)串行口方式0 拓展并行输出端口 02    74LS164芯片
			1.先讲解74LS164 移位芯片: 74HC164.74HCT164 是 8 位边沿触发式移位寄存器,串行输入数据,然后并行输出. 数据通过两个输入端(DSA 或 DSB)之一串行输入:任一输入端可 ... 
- OBD K线抓包 III
			14230 HL激活, 5BPS又称 00 //电平激活 C1 33 F1 81 66 //14230的Enter命令 83 F1 11 C1 EF 8F C4 //回应了,一个命令就回应了... ... 
- 用代码来理解 C#委托与事件
			C#中委托是什么?事件是委托吗? 1.委托是讲方法作为参数代入另一个方法中, 委托可以理解为指向一个函数的引用. class Program { public delegate void Delega ... 
- Shell.xaml
			<Window x:Class="HelloWorld.Shell" xmlns="http://schemas.microsoft.com/winfx/2006/ ... 
- 结对编程—黄金点游戏WinForm单机版
			本小游戏场景来自邹欣老师的<移山之道>一书: "阿超的课都是下午两点钟,这时班上不少的同学都昏昏欲睡,为了让大家兴奋起来,阿超让同学玩一个叫"黄金点"的游戏: ... 
- LR11启动卡修改
			LR11启动卡修改 C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config <runtime>改为<r ... 
