leetcode-第28题-实现strStr()

YOLOv13添加WDBB模块,map提升5.34!!,召回率提升6.55,准确率提升3.23 本文提出了一种基于YOLOv13改进的目标检测模型,通过引入WDBB模块显著提升了检测性能。实验结果表明,添加WDBB模块后,mAP提升11.34,召回率提升14.55,准确率提升3.23。文章详细介绍了模型移植方法,包括创建新的yaml配置文件、修改tasks.py和__init__.py文件,以及实现rep_block.py中的核心转换函数。改进后的模型通过深度卷积、通道注意力等模块优化了特征提取能力,同时保持了轻量化的特点。该工作为YOLO系列模型的性能提升提供了新的思路和技术实现。 阅读详情

博主并没有什么算法基础,所以写的不好,勿喷,抛砖引玉,欢迎交流,感谢。 

//实现 strStr() 函数。 
// 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如
//果不存在,则返回 -1。 
// 示例 1:
// 输入: haystack = "hello", needle = "ll"
//输出: 2
// 示例 2:
// 输入: haystack = "aaaaa", needle = "bba"
//输出: -1
// 说明:
// 当 needle 是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。
// 对于本题而言,当 needle 是空字符串时我们应当返回 0 。这与C语言的 strstr() 以及 Java的 indexOf() 定义相符。
// Related Topics 双指针 字符串 
// 👍 565 👎 0


package com.zqh.leetcode.editor.cn;

//Java:实现 strStr()
public class P28ImplementStrstr {
    public static void main(String[] args) {
        Solution solution = new P28ImplementStrstr().new Solution();
//        System.out.println(solution.strStr("hello", "ll"));
//        System.out.println(solution.strStr("aaa", "aaaa"));
        System.out.println(solution.strStr("aaaaa", "bba"));
//        System.out.println(solution.strStr("mississippi", "pi"));
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int strStr(String haystack, String needle) {
//            方案1:indexOf
//            return haystack.indexOf(needle);

//            超级慢的方案二:先获取所有与needle等长的字符串,然后在判断是否一致
//            if ("".equals(needle) || haystack.equals(needle)) {
//                return 0;
//            }
//            if (haystack.length() < needle.length()) {
//                return -1;
//            }
//            String[] split = haystack.split("");
//            String[] array = new String[split.length - needle.length() + 1];
//            for (int i = 0; i < split.length - needle.length() + 1; i++) {
//                array[i] = split[i];
//                for (int j = 1; j < needle.length(); j++) {
//                    array[i] += split[i + j];
//                }
//                if (array[i].equals(needle)) {
//                    return i;
//                }
//            }
//            return -1;
//            方案三:使用char[]直接在循环里面判断
            if ("".equals(needle) || haystack.equals(needle)) {
                return 0;
            }
            if (haystack.length() < needle.length()) {
                return -1;
            }
            char[] haystackChars = haystack.toCharArray();
            char[] needleChars = needle.toCharArray();
            for (int i = 0; i < haystackChars.length - needleChars.length + 1; i++) {
                boolean flag = true;
                for (int j = 0; j < needleChars.length; j++) {
                    if (haystackChars[i + j] != needleChars[j]) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    return i;
                }
            }
            return -1;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}

 

14、多层螺旋 CT 技术详解 本文详细解析了多层螺旋CT(MSCT)技术的原理与应用,涵盖其相对于单层螺旋CT的优势,包括图像采集速度提升、分辨率提高和噪声降低。文章深入探讨了扫描仪的几何结构、离散投影模型以及关键参数如切片宽度和螺距的影响,并重点介绍了z-滤波重建算法及其离散实现流程。通过流程图和公式推导,系统梳理了从投影获取到图像重建的全过程。同时分析了MSCT在临床中的实际应用案例及未来发展趋势,如更高分辨率、更低辐射剂量和智能化算法等方向,全面展示了MSCT在现代医学影像中的核心价值。 阅读详情

相关推荐

手把手教你逆向抖店滑块验证码:从抓包到生成captchaBody的完整流程(附Python复现代码)

本文详细解析了抖店滑块验证码的逆向过程,从抓包分析到参数生成,最终用Python完整复现验证流程。涵盖关键接口分析、指纹参数生成、轨迹加密逻辑及核心加密算法实现,帮助开发者突破抖店的多重安全机制,实现高效的人机验证绕过。

weixin_30681121的博客 424

leetcode第28题实现strStr()

概述 暑假期间,腆着脸皮面了字节跳动的暑期夏令营活动,被虐很惨,发现好多基础的算法题目都已经忘记了,而基本上笔试和面试考察的都是算法、操作系统等计算机基础知识。因此在后续的学习过程中,需要调整重点,将自己的精力放到刷题上面来,毕竟下半学期如果要出去实习算法和操作系统等基础知识是不可或缺的。 闲话少叙,下边来看下leetcode的第28题,具体题目如下: 实现strStr()函数。 给定一个...

Startapi的博客 511

jemalloc实战:5分钟搞定C程序内存泄漏检测(附PDF报告生成技巧)

本文详细介绍了使用jemalloc的heap profiling功能快速检测C/C++程序内存泄漏的实战方法。通过预编译库和LD_PRELOAD注入,无需修改代码即可启动低开销剖析,并利用jeprof工具进行深度分析和生成可视化PDF报告,帮助开发者高效定位线上或开发环境中的内存问题。

i3j4k5的博客 224

【字符串】【KMP】leetcode28—实现strStr()

基础知识: next数组出现的原因:如果暴力匹配,发现不匹配时,需要从头开始匹配。而有前缀表(即:next数组)之后,当前位置匹配失败,可以通过next数组找到之前已经匹配的内容,从已匹配内容开始匹配。所以next数组的作用即为:在某个字符匹配失败时,next数组可以告诉你下一步匹配时,模式串应该跳到哪个位置。 前缀:不包含最后一个字符的所有以第一个字符开头的连续子串。 后缀:不包含第一个字符的所有以最会一个字符结尾的连续子串。 前缀表:最长相等前后缀的长度。 题目: 实现 strStr() 函数。 给你两

jqq125的博客 149

WeDetect:基于视觉-语言检索的目标检测新范式

目标检测正从传统回归与分类耦合范式,向开放、灵活、可扩展的多模态检索范式演进。检索式检测(Retrieval-based Detection)将检测任务重构为视觉特征与文本语义的联合匹配过程,依托候选框索引库与双塔架构,天然支持开放词汇、零样本识别与小目标定位。其技术价值在于解耦空间感知与语义理解,消除NMS与anchor匹配等冗余计算,显著提升推理效率与跨场景泛化能力。典型应用场景包括工业质检中的缺陷新增识别、遥感图像小目标检测、低光照鲁棒视觉系统等。WeDetect正是这一范式的代表性实现,深度融合视觉

weixin_30878501的博客 361

告别拼音!用VSCode+Dosbox-X搞定汇编语言课程设计里的中文姓名显示

本文详细介绍了如何利用VSCode和Dosbox-X解决汇编语言课程设计中中文姓名显示的问题。通过配置开发环境、理解GB2312编码及正确使用汇编指令,学生可以告别拼音显示,实现中文字符的正确输出。文章还提供了完整的代码示例和常见问题排查方法,帮助读者快速掌握这一实用技能。

weixin_30872337的博客 424

Leetcode刷题记录28——缺失的第一个正数

这种思想的核心在于:将原始数组作为隐式的哈希表来使用,把每个数字放到它应该出现的位置上(如数字 x 放到索引 x - 1 处),这样就能通过一次遍历找到缺失的最小正整数。我们可以使用一个哈希集合(set)来记录nums中所有存在的整数,然后从 1 开始依次检查这些数字是否存在于集合中,一旦发现某个数字不存在,就返回它。这种方法虽然没有达到最优的空间复杂度(O(1)),但它的实现简单、逻辑清晰,适用于大多数场景,特别是对时间和思维成本有限制的情况下。:O(n),因为使用了一个哈希集合保存所有不重复的元素。

weixin_51418895的博客 1195

Python爬取拼多多商品数据保姆级教程(附源码及效果图)

本文介绍了使用Python爬取拼多多商品数据的完整教程。通过DrissionPage库模拟浏览器操作,利用正则表达式提取嵌入在HTML中的商品数据(关键步骤是从window.rawData变量获取),解析后转换为结构化数据并导出Excel。教程包含八大步骤:环境配置、浏览器初始化、网络监听、搜索模拟、数据提取(核心是正则匹配JSON)、数据验证、字段解析和Excel导出,最后提供了封装好的函数可直接调用。该方法特别适合课程作业或毕业设计获取电商数据,能爬取商品名称、价格、销量等关键信息,处理了价格单位转换等

weixin_46449236的博客 2076

怒刷LeetCode的第28天(Java版)

怒刷LeetCode的第28天(Java版)

m0_74293254的博客 520

中国土地市场网爬取

实习期间老板需要对土地数据进行爬取,想来想去就Google到了.应该算是种类最齐全的土地数据了。Github地址:https://github.com/AnTi-anti/china_land/tree/master。

猫敷雪 5462

华为od 面试八股文_操作系统_01_含答案

华为od 面试八股文_操作系统_01_含答案

MISAYAONE的博客 3269

LeetCode第28题

实现 strStr() 函数。 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回  -1。 示例 1: 输入: haystack = "hello", needle = "ll" 输出: 2 示例 2: 输入: haystack = "aaaaa", needl...

Chivalrous man 407

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

LeetCode力扣真题解惑第1篇 —— 力扣第28题:实现 strStr()函数

LeetCode力扣真题解惑第1篇 —— 实现 strStr() 28. 实现 strStr() 函数。 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 -1。 示例 1: 输入: haystack = “hello”, needle = “ll” 输出: 2 示例 2: 输入: haystack = “aaaaa”, needle = “bba” 输出: -1 说明: 当 need

浮生若梦,云游四方 492

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

strstr函数c语言库函数_LeetCode力扣真题解惑第1篇 —— 力扣第28题:实现 strStr()函数...

LeetCode力扣真题解惑第1篇 —— 力扣第28题:实现 strStr()函数28. 实现 strStr() 函数。给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 -1。示例 1:输入: haystack = “hello”, needle = “ll”输出: 2示例 2...

weixin_35823441的博客 207

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

LeetCode第28题:实现strStr()

LeetCode第28题:实现strStr() 题目 实现 strStr() 函数。 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 -1。 示例 1: 输入: haystack = “hello”, needle = “ll” 输出: 2 示例 2: 输入: hay...

不写代码的博客 265

LeetCode28题 实现strStr() C语言

LeetCode28题 实现strStr() C语言 实现 strStr() 实现 strStr() 函数。 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 -1。 示例 1: 输入: haystack = “hello”, needle = “ll” 输出: 2 示例 2: 输入: haystack = “aaaaa”, needle = “bba” 输出: -1 说明: 当

weixin_45356258的博客 243

利用KMP算法解决LeetCode第28题:实现strStr()

文章目录简介算法分析和暴力法的区别重点和难点分析next数组如何求实战:实现strStr()(LeetCode第28题)题目描述示例代码参考 简介 KMP算法是一种字符串匹配算法,由D.E.Knuth,J.H.Morris和V.R.Pratt同时发现,因此人们称它为克努特——莫里斯——普拉特操作(简称KMP算法)。KMP算法的关键是利用匹配失败后的信息,尽量减少模式串与主串的匹配次数以达到快速匹...

FengZH的博客 613

LeetCode 第28题 实现strStr() - KMP算法实现

@[TOC](LeetCode 第28题 实现strStr() 做题记录) 题目描述 我的解法 思路 最直接的方法——暴力求解 两层循环,时间复杂度O(mn) m和n分别是两个字符串的长度 上面超出时间限制了,那就不得不用KMP算法了 对应Java代码 执行时超出了时间限制 class Solution { public int strStr(String haystack, String needle) { if(needle == null || needle.length(

SOS团成员A 181

Leetcode第28题:实现 strStr()【python】

探讨暴力匹配、KMP和Rabin-Karp算法解决字符串搜索问题,分析其时间空间复杂度,优劣势,以选择最适合的方法。

10年数据\经营分析经验,现任大厂数据分析负责人 1099

20210509力扣第28题实现strStr()

1.题目 实现strStr()函数。 给你两个字符串haystack 和 needle ,请你在 haystack 字符串中找出 needle 字符串出现的第一个位置(下标从 0 开始)。如果不存在,则返回-1 。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/implement-strstr 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 说明: 当needle是空字符...

EenKine的博客 306

leetcode 第28题 实现strStr()函数

实现 strStr() 函数。 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 -1。 示例 1: 输入: haystack = “hello”, needle = “ll” 输出: 2 示例 2: 输入: haystack = “aaaaa”, needle = “bba...

云飞扬的博客 193

【LeetCode简单题28】10-实现strStr()

声明 添加要改颜色的字体 添加要改颜色的字体 添加要改颜色的字体 添加要改颜色的字体 题目 实现 strStr() 函数。 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 -1。 示例 1: 输入: haystack = “hello”, needle = ...

时间停止的那刻 245

Leetcode刷题-28:实现 strStr()

解题思路1.题目描述2.题目分析3.题目解答3.1 调用库方法3.2 暴力解法3.3 kmp算法 1.题目描述 2.题目分析 3.题目解答 3.1 调用库方法 class Solution { public: int strStr(string haystack, string needle) { return haystack.find(needle); } }; 3.2 暴力解法 class Solution { public: int strStr(strin

ITSOK_123的博客 764

leetcode-第28题 实现 strStr()

题目 实现strStr()函数。 给定一个haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回-1。 示例 1: 输入: haystack = "hello", needle = "ll" 输出: 2 示例 2: 输入: haystack = "aaaaa", needle = "bba" 输出: -1 来源:力扣(LeetCode) 链接:https://leetcode-c...

lijianqingfeng的专栏 174

力扣--28. 实现 strStr() (简单题)

力扣--28. 实现 strStr【题目描述】【示例】【暴力搜索】【思路】【代码】 (简单题) ) 今天的第二道简单题,先用了暴力搜索法,耗时比较长。 【题目描述】 实现 strStr() 函数。 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 -1。 原题传送门 【示例】 示例 1: 输入: haystack = “hello”, needle = “ll” 输出: 2 示例

Catherinyy的博客 399

力扣刷题之路 28. 实现 strStr() Python解

实现 strStr() 函数。 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 -1。 示例 1: 输入: haystack = “hello”, needle = “ll” 输出: 2 示例 2: 输入: haystack = “aaaaa”, needle = “bba” 输出: -1 说明: 当 needle 是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。 对

Miku_wx的博客 465
上一篇: leetcode-第35题-搜索插入位置
下一篇: leetcode-第26题-删除排序数组中的重复项
97牛肉面
博客等级 码龄9年 54粉丝 75原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值