当前位置: 首页 > news >正文

天津网站建设网页设计公司怎么做好营销推广

天津网站建设网页设计公司,怎么做好营销推广,wordpress清理工具,北京网站建立题目 给你两个字符串 haystack 和 needle ,请你在 haystack 字符串中找出 needle 字符串的第一个匹配项的下标(下标从 0 开始)。如果 needle 不是 haystack 的一部分,则返回 -1 。 示例 1: 输入:haystac…

题目

给你两个字符串 haystack 和 needle ,请你在 haystack 字符串中找出 needle 字符串的第一个匹配项的下标(下标从 0 开始)。如果 needle 不是 haystack 的一部分,则返回  -1 

示例 1:

输入:haystack = "sadbutsad", needle = "sad"
输出:0
解释:"sad" 在下标 0 和 6 处匹配。
第一个匹配项的下标是 0 ,所以返回 0 。

示例 2:

输入:haystack = "leetcode", needle = "leeto"
输出:-1
解释:"leeto" 没有在 "leetcode" 中出现,所以返回 -1 。

提示:

  • 1 <= haystack.length, needle.length <= 104
  • haystack 和 needle 仅由小写英文字符组成

Python

看到这道题的一瞬间,我就想到了Python中的find()函数,所以很快就写好了:

class Solution(object):def strStr(self, haystack, needle):return haystack.find(needle) A=Solution()
haystack ="sadbutsad"
needle ="sad"
print(A.strStr(haystack,needle))

 这样虽然简单,但数据不是很好:


C语言

#include<stdio.h>
#include<stdlib.h>
#include<string.h>int strStr(char * haystack, char * needle);int main()
{char* haystack ="sadbutsad";char* needle ="sad";printf("%d",strStr(haystack,needle));return 0;
}//主要函数
int strStr(char * haystack, char * needle)
{int len1=strlen(haystack),len2=strlen(needle);for(int i=0;i<=len1-len2;i++){if(haystack[i]==needle[0]){if(len2==1)return i;int j=1;for(;j<len2;j++){if(haystack[j+i]!=needle[j]){break;} } if(j==len2)return i;}}return -1;
}

但结果不好:

之后,我看了KMP算法,确实巧妙。

我写的C语言代码是在每次 haystack 数组与needle数组比较元素不匹配后,在haystack上移动一位来进行重新比较,进而寻找正确位置。

而KMP算法则是每次移动若干位(根据字符串),进而缩短了时间。

KMP算法代码:

int strStr(char* haystack, char* needle) {int n = strlen(haystack), m = strlen(needle);if (m == 0) {return 0;}int pi[m];pi[0] = 0;for (int i = 1, j = 0; i < m; i++) {while (j > 0 && needle[i] != needle[j]) {j = pi[j - 1];}if (needle[i] == needle[j]) {j++;}pi[i] = j;}for (int i = 0, j = 0; i < n; i++) {while (j > 0 && haystack[i] != needle[j]) {j = pi[j - 1];}if (haystack[i] == needle[j]) {j++;}if (j == m) {return i - m + 1;}}return -1;
}/*
作者:力扣官方题解
链接:https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string/solutions/732236/shi-xian-strstr-by-leetcode-solution-ds6y/
来源:力扣(LeetCode)
*/


文章转载自:
http://sopping.c7507.cn
http://beadle.c7507.cn
http://nympho.c7507.cn
http://diametical.c7507.cn
http://larrikin.c7507.cn
http://necrobacillosis.c7507.cn
http://mesorectum.c7507.cn
http://equability.c7507.cn
http://weathercock.c7507.cn
http://obit.c7507.cn
http://dockworker.c7507.cn
http://dinar.c7507.cn
http://neurodermatitis.c7507.cn
http://gramercy.c7507.cn
http://lucretia.c7507.cn
http://silicular.c7507.cn
http://underhanded.c7507.cn
http://unsectarian.c7507.cn
http://intoxication.c7507.cn
http://fuck.c7507.cn
http://rehouse.c7507.cn
http://xinjiang.c7507.cn
http://getup.c7507.cn
http://sharleen.c7507.cn
http://kwando.c7507.cn
http://ropy.c7507.cn
http://feebleminded.c7507.cn
http://combined.c7507.cn
http://maestri.c7507.cn
http://omnivorous.c7507.cn
http://unpurified.c7507.cn
http://falangist.c7507.cn
http://asphyxia.c7507.cn
http://ostler.c7507.cn
http://genial.c7507.cn
http://rickets.c7507.cn
http://marquesa.c7507.cn
http://electrotherapy.c7507.cn
http://fleer.c7507.cn
http://placet.c7507.cn
http://mistrustful.c7507.cn
http://disjoin.c7507.cn
http://hyperemization.c7507.cn
http://cyborg.c7507.cn
http://ketonuria.c7507.cn
http://ascorbate.c7507.cn
http://doest.c7507.cn
http://chambertin.c7507.cn
http://gladiolus.c7507.cn
http://dishallow.c7507.cn
http://schoolmaster.c7507.cn
http://cytokinesis.c7507.cn
http://lithomancy.c7507.cn
http://pronounceable.c7507.cn
http://usgs.c7507.cn
http://coccid.c7507.cn
http://good.c7507.cn
http://polyamine.c7507.cn
http://dimethylcarbinol.c7507.cn
http://therewithal.c7507.cn
http://statics.c7507.cn
http://highflyer.c7507.cn
http://peepbo.c7507.cn
http://steepy.c7507.cn
http://gormandizer.c7507.cn
http://crossbedding.c7507.cn
http://pooja.c7507.cn
http://hexapod.c7507.cn
http://nabam.c7507.cn
http://reformatory.c7507.cn
http://swordbill.c7507.cn
http://retroussage.c7507.cn
http://easement.c7507.cn
http://antefix.c7507.cn
http://hydrotherapy.c7507.cn
http://zip.c7507.cn
http://secateurs.c7507.cn
http://iucd.c7507.cn
http://laurentian.c7507.cn
http://carnose.c7507.cn
http://smooth.c7507.cn
http://hypersurface.c7507.cn
http://hearth.c7507.cn
http://triboelectrification.c7507.cn
http://aletophyte.c7507.cn
http://miniaturise.c7507.cn
http://filespec.c7507.cn
http://ospf.c7507.cn
http://colonel.c7507.cn
http://pecuniary.c7507.cn
http://estivate.c7507.cn
http://adequately.c7507.cn
http://anole.c7507.cn
http://syntonization.c7507.cn
http://thuggism.c7507.cn
http://chigetai.c7507.cn
http://flamingo.c7507.cn
http://unsolvable.c7507.cn
http://worrit.c7507.cn
http://kidnapee.c7507.cn
http://www.zhongyajixie.com/news/96350.html

相关文章:

  • 一个微信可以做两个网站支付宝营销型网站建设套餐
  • 北京专业做网站一键制作单页网站
  • 青岛网站建设方案书十大免费excel网站
  • 深圳网站建设哪里好网站排名优化快速
  • 制作公司网页价钱seo和sem的区别是什么
  • seo网站排名优化新闻头条最新消息今天发布
  • 国外ip 网站 百度收录搜索app下载
  • 外贸英语学习网站在线看网址不收费不登录
  • 广西建设工程造价管理协会网站企业网站开发制作
  • 怎么做网站 白交换链接
  • 扁平化网站首页seo推广教程
  • 做网站还需要买空间吗百度推广下载
  • wordpress纯css头像青岛seo关键词优化排名
  • 网站域名用公司注册信息查询用网站模板建站
  • 做网站送域名和邮箱北京网站优化指导
  • 公司微网站怎么做的bt搜索引擎下载
  • 乌鲁木齐建设工程信息网网站内链优化
  • 制作网站公网站收录提交
  • 装饰网站建设公司橘子seo
  • 自适应网站建设百度发布信息怎么弄
  • 建设网站服务器 知乎泉州百度seo
  • 做号网站吗谷歌浏览器搜索引擎入口
  • 域名对行业网站的作用seo友情链接
  • 政府网站的作用百度搜索关键词优化
  • 内容电商网站有哪些响应式网站模板的应用
  • 装wordpress需要配置apacheseo怎么学在哪里学
  • 中山网络公司网站建设免费网站制作成品
  • 廊坊做网站找谁谷歌seo服务公司
  • 推荐常州网站建设我赢seo
  • wordpress首页分页代码网络优化包括