题目要求:Implement strStr()

Implement strStr().

Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

Java:

    public int strStr(String haystack, String needle) {

        if (haystack == null || needle == null) {
return 0;
} if (needle.length() == 0) {
return 0;
} for (int i = 0; i < haystack.length(); i++) {
if (i + needle.length() > haystack.length()) {
return -1;
} int m = i;
for (int j = 0; j < needle.length(); j++) {
if (needle.charAt(j) == haystack.charAt(m)) {
if (j == needle.length() - 1) {
return i;
}
m++;
} else {
break;
}
}
} return -1; }

LeetCode 028 Implement strStr()的更多相关文章

  1. Java for LeetCode 028 Implement strStr()

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  2. 【LeetCode】028. Implement strStr()

    Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...

  3. [LeetCode] 28. Implement strStr() 实现strStr()函数

    Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...

  4. [leetcode 27]Implement strStr()

    1 题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ...

  5. Leetcode #28. Implement strStr()

    Brute Force算法,时间复杂度 O(mn) def strStr(haystack, needle): m = len(haystack) n = len(needle) if n == 0: ...

  6. 【leetcode】Implement strStr() (easy)

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  7. 【leetcode】Implement strStr()

    Implement strStr() Implement strStr(). Returns the index of the first occurrence of needle in haysta ...

  8. Java [leetcode 28]Implement strStr()

    题目描述: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ...

  9. [LeetCode] 28. Implement strStr() 解题思路

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

随机推荐

  1. linux用户及组相关文件介绍

    用户和组文件介绍 1.用户账号文件:passwd passwd命令用于设置用户的认证信息,包括用户密码.密码过期时间等.系统管理者则能用它管理系统用户的密码.只有管理者可以指定用户名称,一般用户只能变 ...

  2. Python爬虫练习(requests模块)

    Python爬虫练习(requests模块) 关注公众号"轻松学编程"了解更多. 一.使用正则表达式解析页面和提取数据 1.爬取动态数据(js格式) 爬取http://fund.e ...

  3. POJ1840 Eqs

    题意描述 Eqs 求一个五元方程 \(a_1x_1^3+a_2x_2^3+a_3x_3^3+a_4x_4^3+a_5x_5^3=0\) 的解的个数. 题中给出 \(a_i\) 的值并且保证 \(-50 ...

  4. .netcore 简单使用ElasticSearch

    .netcore 简单使用ElasticSearch(7.6) 最近在捣鼓学习了下ElasticSearch,在此记录下使用.netcore操作elastic search 的实现(简单的封装,使用) ...

  5. 通过阿里镜像网站制作iso文件安装CentOS6.9

    基于网络安装 创建kickstart文件的方式: 1.复制模板/root/anaconda-ks.cfg,而后使用vim编辑配置 2.使用system-config-kickstart来生成,建议使用 ...

  6. 直播带货APP源码开发为什么选择云服务器

    云服务器可以为直播带货APP源码提供弹性计算以及更高的运行效率,避免资源浪费,随着直播带货APP源码业务需求的变化,可以实时扩展或缩减计算资源.CVM支持按实际使用的资源计费,可以节约计算成本. 一. ...

  7. 3.3 Spring5源码---循环依赖过程中spring读取不完整bean的最终解决方案

    根据之前解析的循环依赖的源码, 分析了一级缓存,二级缓存,三级缓存的作用以及如何解决循环依赖的. 然而在多线程的情况下, Spring在创建bean的过程中, 可能会读取到不完整的bean. 下面, ...

  8. Pandas_工资集处理

    import numpy as np import pandas as pd from pandas import Series,DataFrame # 1--读取数据文件 file_obj=open ...

  9. 主动关闭 tcp fin-wait-2 time-wait 定时器

    后面整理相关信息 //后面整理相关信息 /* * This function implements the receiving procedure of RFC 793 for * all state ...

  10. Apache Shiro (Shiro-550)(cve_2016_4437)远程代码执行 - 漏洞复现

    0x00 漏洞原理 Apache Shiro框架提供了记住密码的功能(RememberMe),用户登录成功后会生成经过加密并编码的cookie.在服务端对rememberMe的cookie值, 先ba ...