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 ...
随机推荐
- ghj1222的代码规范
基本上和notepad++的要求一样. 不定期更新. 1.左大括号换行: int main() { return 0; } 可能有些同志(比如大佬cjh)和我的做法不一样 当一个函数很短的时候可以整个 ...
- git 打tag
查看已有tag git tag 创建新的tag git tag <version or tagname> -m <tag description> 例如创建一个版本1.0.0的 ...
- linux下mysql的安装部署
---恢复内容开始--- 注意这一切都是root用户下进行的 su root * 一.查看之前是否安装过:yum list installed mysql* 二.查看是否有安装包:yum list ...
- JAVA第二个程序
关于计算基础问题华氏度与摄氏度互相转化问题 题目内容: 写一个将华氏温度转换成摄氏温度的程序,转换的公式是: °F = (9/5)*°C + 32 其中C表示摄氏温度,F表示华氏温度. 程序的输入是一 ...
- POJ 3067 Japan (树状数组 && 控制变量)
题意: 西海岸和东海岸有分别有n (1~n)个和m (1~m)个城市, 两个海岸的城市之间有k条公路连通, 公路会相交, 现在给出城市和公路的信息问你由这些公路组成的复杂交通有多少个交点 (如果两个条 ...
- Android_靠谱的监听软键盘状态的方法
public class MyActivity extends AppCompatActivity { /** * 当前界面中的软件盘的状态 */private boolean isKeyBoardO ...
- appium ios 真机自动化环境搭建
近期由于工作需要,本小菜在弄appium+ios+iphone真机的移动自动化,在网上找寻各种资料,发现针对IOS方面的资料少之又少,公司其它部门的弄过的同事也寥寥无几,即使有,也是安卓方面的.本次书 ...
- sqlserver 索引进阶(下)
参考原文 http://www.cnblogs.com/tjy9999/p/4494799.html 第十级, 索引内部结构 建立索引的目的是加快对表中记录的查找或排序.为表设置索引要付出代价的:一是 ...
- Apache HttpClient 4.3.6 API
官网:http://hc.apache.org/httpcomponents-client-4.3.x/httpclient/apidocs/overview-summary.html 使用教程转载: ...
- spring aop execution用法
代码结构: 1. "execution(* com.ebc..*.*(..))" 与 "execution(* com.ebc..*(..))" 2019-0 ...