实现在一个母字符串中找到第一个子字符串的位置。

#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】的更多相关文章

  1. Implement strStr() [LeetCode]

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

  2. Implement strStr() leetcode java

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

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

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

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

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

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

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

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

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

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

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

  8. 【LeetCode】Implement strStr()(实现strStr())

    这道题是LeetCode里的第28道题. 题目描述: 实现 strStr() 函数. 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle ...

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

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

随机推荐

  1. jupyter notebook 设置默认目录

    1.打开 cmd 输入命令 jupyter notebook --generate-config 可以看到生成文件的路径,这个就是生成的配置文件jupyter_notebook_config.py, ...

  2. 添加fping监控

    第一步:安装fping服务 yum -y install fping 第二步:在zabbix-server服务端上启用fping服务 重启zabbix-server 第三步:在主机上添加fping监控 ...

  3. nginx 搭建 rtmp 服务器

    前言 最近接手了一个跟视频监控相关的项目,用了近年来越来越流行的 Web 服务器 nginx 加上 nginx-rtmp-module 搭建 rtmp 服务器.使用了阿里云的服务器,系统 Ubuntu ...

  4. poj2513连接木棍(字典树+欧拉回路+并查集)

    题目传送门 题目大意:给你一堆木棍,每根木管都有两种颜色,相同颜色的部分可以连接起来,问你这堆木棍可不可以连接成1根. 思路:大致的思路很好想,就是判断欧拉回路的方法(1.联通,2,要么顶点读书全为偶 ...

  5. CentOS快速搭建FTP(初级-四步)

    部署FTP,如果之前没有搭建过,刚开始找资料的时候网上各种各样的复杂参数配置,看的头晕,这里就把最核心的部分展示出来. 1.安装 vsftpd yum install -y vsftpd 2.如果是默 ...

  6. hau 1870 愚人节的礼物(栈)

    愚人节的礼物 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  7. 测试转型之路--学习ing

    http://www.importnew.com/27309.html 测试开发工程师 - 抖音方向 职位描述1.深度参与产品研发项目, 协同产品经理.业务研发.用户反馈团队优质交付产品:2.参与质量 ...

  8. 解决ifconfig没有网卡问题

    ifconfig -a root@kali:~# ifup eth0 ifup: unknown interface eth0 vim /etc/network/interfaces #自行添加网卡 ...

  9. 配置MapReduce程序运行环境

    已安装eclipse,hadoop 查看教程dblab.xmu.edu.cn/blog/hadoop-build-project-using-eclipse/

  10. java——设计一个支持push,pop,top、在恒定时间内检索最小元素的栈。

    普通方法: 需要另外一个栈 用来存放每一时刻的min值 巧妙版: 只需要一个stack,stack中存的是与min的差值 但由于min是两个整数之间的差值,有可能会出现差值超过整数边界值的情况,因此要 ...