LeetCode 28Implement strStr() 寻找子字符串的下标的位置
来源:互联网 发布:社交网络的利弊 英文 编辑:程序博客网 时间:2024/05/21 08:04
题目要求:
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
题目不难,可以直接使用暴力搜索的方式进行处理
public class solution { public int strStr(String haystack, String needle) { //使用暴力搜索的方式进行求解 int l1 = haystack.length(); int l2 = needle.length(); if(l1 == l2 && l1 == 0) return 0; int j = 0; for(int i = 0; i <= l1 - l2; i++) { for(j = 0; j < l2; j++) { if(haystack.charAt(i + j) != needle.charAt(j)) break; } if(j == l2) return i; } return -1; }}
1 0
- LeetCode 28Implement strStr() 寻找子字符串的下标的位置
- [C++]Implement strStr() 找到子字符串第一次出现的位置
- 28. Implement strStr() (返回子串在字符串中第一次出现的位置)
- LeetCode 28 Implement strStr()(子字符串查找)
- [LeetCode] Implement strStr() 字符串子串
- LeetCode | 28. Implement strStr()——寻找子串
- LeetCode-28 Implement strStr() (找出字串位置)
- leetcode---implement-strstr---字符串
- leetcode 子串位置的寻找
- LeetCode-28-Implement strStr()(字符串匹配)
- 28. Implement strStr()找子串的位置
- 28.LeetCode Implement strStr()(meidum)[字符串 子串匹配]
- [LeetCode]Implement strStr() 字符串匹配
- leetcode 字符串匹配Implement strStr()
- [LeetCode] Implement strStr()[字符串hash]
- (LeetCode)Implement strStr() --- 匹配字符串
- LeetCode(28)Implement Strstr()
- [leetcode 28] Implement strStr()
- 无线信号穿墙能力
- 二进制的源码 补码 反码
- 快速排序
- python之sys.argv 用法解析
- HDU 1565 方格取数(1) 二分图最大点权独立集
- LeetCode 28Implement strStr() 寻找子字符串的下标的位置
- 【C语言】每瓶汽水1元,两个空瓶可以置换一瓶汽水,现在有20元,最多能喝多少瓶汽水。
- Lightoj 1414 - February 29 (闰年统计,容斥定理)
- LeetCode 398. Random Pick Index
- Poj3126 prime
- iphone,ipad各个版本的跑分,iphone7,iphone 8 pluse,ipad Pro,iphone4,iphone4s,ipad, iphone 6,iphone 6s,
- CNKI e study 去除word插件
- hysbz1008 越狱(组合数学)
- 两个矩阵相乘—Strassen算法(矩阵为偶数阶方阵)