博客
关于我
LC-实现函数 strStr
阅读量:691 次
发布时间:2019-03-17

本文共 663 字,大约阅读时间需要 2 分钟。

实现函数 strStr

/*实现函数 strStr函数声明如下:char *strStr(char *str, char *dest)返回一个指针,指向dest第一次在str中出现的位置,如果dest不是str的子串,则返回null*/#include
#include
#include
using namespace std;class Solution { public: char *strStr(char *str, char *dest) { if (str == NULL && dest == NULL) return NULL; if (str == NULL || dest == NULL) return NULL; size_t result = strStrImpl(str, dest); if (result == -1) return NULL; char* resPtr = str; size_t index = 0; while (index < result) { index++; resPtr++; } return resPtr; } char strStrImpl(string str, string dest) { size_t res = str.find(dest); return (res != str.npos) ? res : -1; }};

转载地址:http://swchz.baihongyu.com/

你可能感兴趣的文章
mysql函数遍历json数组
查看>>
mysql分区表
查看>>
MySQL分层架构与运行机制详解
查看>>
MySQL分组查询
查看>>
Mysql分表后同结构不同名称表之间复制数据以及Update语句只更新日期加减不更改时间
查看>>
Mysql基础命令 —— 系统操作命令
查看>>
mysql备份
查看>>
mysql备份与恢复
查看>>
MySQL外键约束
查看>>
MySQL多表关联on和where速度对比实测谁更快
查看>>
mysql大批量删除(修改)The total number of locks exceeds the lock table size 错误的解决办法
查看>>
MySQL如何实现ACID ?
查看>>
mysql存储登录_php调用mysql存储过程会员登录验证实例分析
查看>>
MySQL存储过程入门
查看>>
mysql存储过程批量建表
查看>>
mysql存储过程详解
查看>>
MySQL学习-group by和having
查看>>
MySQL学习-MySQL条件查询
查看>>
MySQL学习-子查询及limit分页
查看>>
MySQL学习-排序与分组函数
查看>>