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 ...
随机推荐
- javascript小菜单—demo
<!DOCTYPE html><html><head> <title></title></head><body>&l ...
- CF796B Find The Bone
Zane the wizard is going to perform a magic show shuffling the cups. There are n cups, numbered from ...
- 字串变换 bfs + 字符串
题目描述 已知有两个字串A,BA,BA,B及一组字串变换的规则(至多666个规则): A1A_1A1 ->B1 B_1B1 A2A_2A2 -> B2B_2B2 规则的含义为:在 ...
- Codeforces Round #521 (Div. 3) C. Good Array
C. Good Array time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- .net mvc 框架实现后台管理系统 3
左侧菜单实现 默认html <div class="layui-side layui-bg-black h-slide"> <div class="la ...
- JavaScript Succinctly 读后笔记
1.JavaScript does not have block scope 2.Scope is determined during function definintion, not invo ...
- C语言把字符串转换为数字
C当中有一些函数专门用于把字符串形式转换成数值形式. printf()函数和sprintf()函数 -->通过转换说明吧数字从数字形式转换为字符串形式: scanf()函数把输入字符串转换为数值 ...
- C/C++中qsort()以及sort()的用法
最近学弟们问快速排序的比较多,今天自己就做一下总结,快速排序在库函数里面有现成的,不用自己实现,调用一下就可以达到自己想要的结果,掌握以后就可以完全摒弃冒泡和选择了,并且时间复杂度也从O(n*n)提升 ...
- Laravel5.1接收json数据
<?php namespace App\Http\Controllers;use Illuminate\Routing\Controller as BaseController; use Ill ...
- c++中enum 如何使用(转)
ENUM概况 enum枚举类型是C/C++中的一种数据类型,与struct和class一样是用户自定义的类型,其特点在于enum类型的变量取值是有限的,是可以一一列举出来的. ENUM定义 C++ e ...