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 ...
随机推荐
- mybatis 遍历字段和字段对应的值循环插入
java代码: /** * 插入单条数据 * @param request * @param response * @param id * @param str * @return * @throws ...
- Unity组件
在学习C++的时候,对于面对对象有点了解.然后也使用过一段时间的Unity,用起来还是觉得,怎么这么好用.耦合性极低.当时不知道这是基于组件编程.所以现在来学习下基于组件的知识,并比较下基于组件和基于 ...
- fiddler抓包出现错误 creation of the root certificate was not successful
fiddler安装完要配置才可以抓取HTTP 1.首先 找到Tools——>Options,在弹出的菜单中 选择https项 勾选捕捉https,这样配置完OK之后 一般会弹窗提示安装证书,点击 ...
- lvs 中DR模式负载均衡及keepalived
lvs DR配置 LVS负载均衡:三种负载均衡模式:DR,TUN(ip隧道),NAT,这里我们介绍DR模式 server1: 首先,配置server机yum源 方便后期实验流畅vim /etc/yum ...
- kohana reading session data error(session_start)引起的错误
在项目中碰到一个很奇怪的问题,同一个网站目录下两个项目,手机端访问从A项目切换到B项目,总是报错,session_start抛错,后来排查了很久,终于发现是存储session的时候直接存储的对象,导致 ...
- STL effectiv 条款7 复习 未完成
该条款很好的解决了 容器中存放指针释放的问题,for_each函数调用可以参考自己的前面的博客 为什么会有这个条款呢 很多时候 我们将new过的指针存放到容器中,我们有时候错误的认为 容器对象析构 ...
- oracle命令查看表结构及表索引
--查看oracle数据库的单个表结构 select dbms_metadata.get_ddl('TABLE','TABLE_NAME') from dual; 括号里面有两个参数,第一个参数是我们 ...
- pip安装flask问题解决
环境:python 2.7 pip install virtualenv pip install flask 提示成功但无效 查看http://docs.jinkan.org/docs/flask/i ...
- 性能测试工具LoadRunner22-LR之Analysis 简介
Analysis功能: 对测试运行结果进行查看.分析和比较 导入分析文件 注意LoadRunner Results文件和Analysis Session Files的区别.LoadRunner Res ...
- 性能测试工具LoadRunner02-LR简介
使用LoadRunner的步骤 制定性能测试计划-->开发测试脚本-->设计测试场景-->执行测试场景-->监控测试场景-->分析测试结果 LoadRunner由哪些部件 ...