博客
关于我
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索引、索引优化(这一篇包括所有)
查看>>
Mysql索引一篇就够了
查看>>
MySQL索引一篇带你彻底搞懂(一次讲清实现原理加优化实战,面试必问)
查看>>
MySQL索引下沉:提升查询性能的隐藏秘
查看>>
MySql索引为什么使用B+树
查看>>
MySQL索引为什么是B+树
查看>>
WARNING!VisualDDK wizard was unable to find any DDK/WDK installed on your system.
查看>>
MySQL索引介绍及百万数据SQL优化实践总结
查看>>
Mysql索引优化
查看>>
MySQl索引创建
查看>>
mysql索引创建及使用注意事项
查看>>
mysql索引创建和使用注意事项
查看>>
MySQL索引原理以及查询优化
查看>>
Mysql索引合并(index merge)导致的死锁问题
查看>>
MySQL索引和查询优化
查看>>
mysql索引底层数据结构和算法
查看>>
Mysql索引底层结构的分析
查看>>
MySQL索引底层:B+树详解
查看>>
Mysql索引总结
查看>>
mysql索引最左匹配原则理解以及常见的sql使用的索引情况的实测
查看>>