c语言 Implement strStr()【Leetcode】
实现在一个母字符串中找到第一个子字符串的位置。
#include <stdio.h>
#include <string.h>
#define _IRON_TRUE 1
#define _IRON_FALSE 0
typedef int BOOL;
int strStr(char* s1, char* s2)
{
;
int l1 = strlen(s1);
int l2 = strlen(s2);
) ;
;
, j = ;
; i <= (l1-l2); i++)
{
BOOL successFlag = _IRON_FALSE;
; j < l2; j++)
{
if(*(s1+i+j) != *(s2+j))
{
successFlag = _IRON_FALSE;
break;
}
successFlag = _IRON_TRUE;
}
if(successFlag) return i;
}
;
}
int main(int argc, char* argv[])
{
)
{
printf("please input two str param, the first is haystack and the second is needle\n");
}
];
];
int i = strStr(s1,s2);
printf("%d",i);
}
c语言 Implement strStr()【Leetcode】的更多相关文章
- Implement strStr() [LeetCode]
Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...
- 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】Implement strStr()(实现strStr())
这道题是LeetCode里的第28道题. 题目描述: 实现 strStr() 函数. 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle ...
- LeetCode(28)题解:Implement strStr()
https://leetcode.com/problems/implement-strstr/ 题目: Implement strStr(). Returns the index of the fir ...
随机推荐
- P3398 仓鼠找sugar 树上路径相交判断
\(\color{#0066ff}{题目描述}\) 小仓鼠的和他的基(mei)友(zi)sugar住在地下洞穴中,每个节点的编号为1~n.地下洞穴是一个树形结构.这一天小仓鼠打算从从他的卧室(a)到餐 ...
- From表单提交刷新页面?
form表单提交跳转 写作原因: 楼主的html水平一般,偶然想起周围人常说的form表单提交会刷新页面,闲来无事,就想想其中的原因 想来想去为什么会刷新,猜想了以下几条 1.先提交数据,等服务器 ...
- kuangbin专题七 HDU1698 Just a Hook (区间设值 线段树)
In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. T ...
- php实现页面跳转的几种方式
PHP中实现页面跳转有一下几种方式,看了几个人写的不是很条理,自己整理一下 在PHP脚本代码中实现 <?php header("location:url地址") ?> ...
- Qt 学习之路 2(23):自定义事件
Qt 学习之路 2(23):自定义事件 豆子 2012年10月23日 Qt 学习之路 2 21条评论 尽管 Qt 已经提供了很多事件,但对于更加千变万化的需求来说,有限的事件都是不够的.例如, ...
- 树莓派使用 HLS 实现视频流直播
说明 这次介绍一下基于上一篇文章"树莓派编译安装 FFmpeg "的应用,即 HLS 视频流直播.原理是 FFmpeg 将 USB 摄像头的原始视频流压缩为 H.264 视频流,然 ...
- Linux软件源apt 仓库 包 的概念
概念介绍: 软件源是debian系的概念,把软件放在一个pool里面,用一条命令就可以自动从指定服务器下载并安装. 源列表是/etc/apt/sources.list,里面写了你所用的服务器地址 (其 ...
- Socket通信客户端和服务端代码
这两天研究了下Socket通信,简单实现的客户端和服务端代码 先上winfrom图片,客户端和服务端一样 服务端代码: using System; using System.Collections.G ...
- ubuntu14.04下 安装matlabR2015b遇到的一些问题及其解决方法
问题1:错误提示关于未取得权限,不能再/crack/bin文件中复制文件到安装matlab的/usr/bin文件中? 采取解决方法: 再终端里输入 sudo nautilus,在弹出文件夹里即可进行相 ...
- oracle数据库代码块
--申明变量.游标 declare a ):'; --逻辑 begin INSERT into TEMP_DSF.TEST VALUES (a); end; tips:mysql不支持匿名块.仅在存储 ...