LeetCode 28 Implement strStr() (实现找子串函数)
package leetcode_50; /***
*
* @author pengfei_zheng
* 实现找子串的功能
*/
public class Solution28 {
public int strStr(String haystack, String needle) {
for (int i = 0; ; i++) {
for (int j = 0; ; j++) {
if (j == needle.length()) return i;
if (i + j == haystack.length()) return -1;
if (needle.charAt(j) != haystack.charAt(i + j)) break;
}
}
}
}
LeetCode 28 Implement strStr() (实现找子串函数)的更多相关文章
- 44. leetcode 28. Implement strStr()
28. Implement strStr() Implement strStr(). Returns the index of the first occurrence of needle in ha ...
- [LeetCode] 28. Implement strStr() 实现strStr()函数
Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...
- [LeetCode] 28. Implement strStr() 解题思路
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- [LeetCode] 28. Implement strStr() ☆
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- Leetcode #28. Implement strStr()
Brute Force算法,时间复杂度 O(mn) def strStr(haystack, needle): m = len(haystack) n = len(needle) if n == 0: ...
- Java [leetcode 28]Implement strStr()
题目描述: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ...
- Leetcode 28——Implement strStr()
Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...
- [leetcode]28. Implement strStr()实现strStr()
Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...
- LeetCode——28. Implement strStr()
题目: class Solution { public: int strStr(string haystack, string needle) { if(needle.empty()){ return ...
随机推荐
- DbHelper.ttinclude 更新,查询视图和表
<#+ public class DbHelper { #region GetDbTables public static List<DbTable> GetDbTables(str ...
- VS 调试 无法启动IIS Express Web 服务器(进程不存在)
拷贝VS2015项目 出现无法启动IIS Express Web 服务器 一.把你们拷贝刀本机的解决方案文件中的隐藏文件夹.vs删除掉 重新生产解决方案就可以启动iis express了.
- Http协议中常用字段总结(不定时完善中)
1.Http协议概述 关于Http协议的发展,各种资料有很多,在此不再赘述,不明白的小伙伴儿可以去搜一下,Http报文分为请求报文和相应报文,由于Http是面向文本的,因此在报文中的每一个字段都是一些 ...
- u3d 加载PNG做 UI图片
using UnityEngine; using System.Collections; using System.IO; using UnityEngine.UI; public class UIT ...
- 消息队列之 RabbitMQ
https://www.jianshu.com/p/79ca08116d57 关于消息队列,从前年开始断断续续看了些资料,想写很久了,但一直没腾出空,近来分别碰到几个朋友聊这块的技术选型,是时候把这块 ...
- EJB的魅惑来源
有人发帖子问学习EJB有个屁用啊?看完下面一个简单的介绍,也许你对EJB很感兴趣,它的优点极具魅惑力. 一.EJB是基于组件的开发. 利用Enterprise JavaBean,你就能像搭积木一样 ...
- Deferred对象
摘要:虽然js已经出了ES6,ES7等等版本,从而也诞生了新的异步对象->promise,但是基础还是要终结的,这一片就来回顾一下ajax以及ajax的异步对象->deferred. 1. ...
- Backlight当前行背景高亮显示
下载地址:https://github.com/limejelly/Backlight-for-XCode PS:Xcode 8.0 默认支持了 跟VVDocumenter规范注释生成器的安装方式一样 ...
- Spring Boot 处理 REST API 错误的正确姿势
摘要:如何正确的处理API的返回信息,让返回的错误信息提供更多的含义是一个非常值得做的功能.默认一般返回的都是难以理解的堆栈信息,然而这些信息也许对于API的客户端来说有可能并没有多大用途,并没有多大 ...
- 17 HTTP编程入门
http请求原理 http请求原理我就不多说了,网上一搜就能搜索到,下面我注意是记录下http模块的使用方法 http 模块 HTTP-server hello world 我们使用HandleFun ...