Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit079bb7d

Browse files
committed
28-find-the-index-of-the-first-occurrence-in-a-string.md Separated Chinese and English solutions.
1 parenteae8934 commit079bb7d

File tree

3 files changed

+47
-80
lines changed

3 files changed

+47
-80
lines changed

‎en/1-1000/28-find-the-index-of-the-first-occurrence-in-a-string.md

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
#28. Find the Index of the First Occurrence in a String - Best Practices of LeetCode Solutions
2-
LeetCodeEnglishlink:[28. Find the Index of the First Occurrence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string)
2+
LeetCode link:[28. Find the Index of the First Occurrence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string), difficulty:**Easy**.
33

4-
LeetCode Chinese link:[28. 找出字符串中第一个匹配项的下标](https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string)
5-
6-
[中文题解](#中文题解)
7-
8-
##LeetCode problem description
4+
##Description of "28. Find the Index of the First Occurrence in a String"
95
Given two strings`needle` and`haystack`, return the**index** of the first occurrence of`needle` in`haystack`, or`-1` if`needle` is not part of`haystack`.
106

11-
Difficulty:**Easy**
12-
137
###[Example 1]
148
**Input**:`haystack = "sadbutsad", needle = "sad"`
159

@@ -33,8 +27,6 @@ The first occurrence is at index 0, so we return 0.
3327
-`haystack` and`needle` consist of only lowercase English characters.
3428

3529
##Intuition
36-
[中文题解](#中文题解)
37-
3830
Traverse the string once, and if the`needle.length` characters after the current position are equal to`needle`, return the current`index`.
3931

4032
##Complexity
@@ -94,22 +86,3 @@ var strStr = function (haystack, needle) {
9486
```
9587
// Welcome to create a PR to complete the code of this language, thanks!
9688
```
97-
98-
##力扣“28. 找出字符串中第一个匹配项的下标”问题描述
99-
力扣链接:[28. 找出字符串中第一个匹配项的下标](https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string), 难度:**简单**
100-
101-
给你两个字符串`haystack``needle` ,请你在`haystack` 字符串中找出`needle` 字符串的第一个匹配项的下标(下标从`0` 开始)。如果`needle` 不是`haystack` 的一部分,则返回`-1`
102-
103-
###[示例 1]
104-
**输入**:`haystack = "sadbutsad", needle = "sad"`
105-
106-
**输出**:`0`
107-
108-
###[示例 1]
109-
**输入**:`haystack = "leetcode", needle = "leeto"`
110-
111-
**输出**:`-1`
112-
113-
#中文题解
114-
##思路
115-
遍历一遍字符串,如果从当前位置起的后的`needle.length`个字符等于`needle`,则返回当前的`index`

‎en/3001-4000/unorganized.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,33 @@ The improved way with a queue is commonly more efficient. Relaxing **All Edges**
114114
- 538https://leetcode.cn/problems/convert-bst-to-greater-tree/
115115

116116
###Backtracking
117-
- 77https://leetcode.cn/problems/combinations/description/
117+
- 77https://leetcode.cn/problems/combinations/
118118
- 216https://leetcode.cn/problems/combination-sum-iii/
119-
- 17https://leetcode.cn/problems/letter-combinations-of-a-phone-number/
120119
- 39https://leetcode.cn/problems/combination-sum/
121-
-
120+
- 17https://leetcode.cn/problems/letter-combinations-of-a-phone-number/
121+
- 78https://leetcode.cn/problems/subsets/
122+
- 90https://leetcode.cn/problems/subsets-ii/
123+
- 40https://leetcode.cn/problems/combination-sum-ii/
124+
- 131https://leetcode.cn/problems/palindrome-partitioning/
125+
- 93https://leetcode.cn/problems/restore-ip-addresses/
126+
- 491https://leetcode.cn/problems/non-decreasing-subsequences/
127+
- 46https://leetcode.cn/problems/permutations/
128+
- 332https://leetcode.cn/problems/reconstruct-itinerary/
129+
- 51https://leetcode.cn/problems/n-queens/
130+
131+
###Greedy Algorithm
132+
- 455https://leetcode.cn/problems/assign-cookies/
133+
- 376https://leetcode.cn/problems/wiggle-subsequence/
134+
- 53https://leetcode.cn/problems/maximum-subarray/
135+
- 122https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-ii/
122136

123137
###Failed in 2 rounds
124138
- 222https://leetcode.cn/problems/count-complete-tree-nodes/
125139
- 236https://leetcode.cn/problems/lowest-common-ancestor-of-a-binary-tree/
140+
- 40https://leetcode.cn/problems/combination-sum-ii/
141+
- 131https://leetcode.cn/problems/palindrome-partitioning/
142+
- 332https://leetcode.cn/problems/reconstruct-itinerary/
143+
- 51https://leetcode.cn/problems/n-queens/
144+
- 37https://leetcode.cn/problems/sudoku-solver
145+
146+
2005-02-04 day 7
Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,37 @@
1-
#28. Find the Index of the First Occurrence in a String - Best Practices of LeetCode Solutions
2-
LeetCode English link:[28. Find the Index of the First Occurrence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string)
3-
4-
LeetCode Chinese link:[28. 找出字符串中第一个匹配项的下标](https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string)
5-
6-
[中文题解](#中文题解)
7-
8-
##LeetCode problem description
9-
Given two strings`needle` and`haystack`, return the**index** of the first occurrence of`needle` in`haystack`, or`-1` if`needle` is not part of`haystack`.
1+
#28. 找出字符串中第一个匹配项的下标 - 力扣题解最佳实践
2+
力扣链接:[28. 找出字符串中第一个匹配项的下标](https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string), 难度:**简单**
103

11-
Difficulty:**Easy**
4+
##力扣“28. 找出字符串中第一个匹配项的下标”问题描述
5+
给你两个字符串`haystack``needle` ,请你在`haystack` 字符串中找出`needle` 字符串的第一个匹配项的下标(下标从`0` 开始)。如果`needle` 不是`haystack` 的一部分,则返回`-1`
126

13-
###[Example 1]
14-
**Input**:`haystack = "sadbutsad", needle = "sad"`
7+
###[示例 1]
8+
**输入**:`haystack = "sadbutsad", needle = "sad"`
159

16-
**Output**:`0`
10+
**输出**:`0`
1711

18-
**Explanation**:
12+
**解释**:
1913
```
20-
"sad"occurs at index 0 and 6.
21-
The first occurrence is at index 0, so we return 0.
14+
"sad"在下标 0 和 6 处匹配。
15+
第一个匹配项的下标是 0 ,所以返回 0 。
2216
```
2317

24-
###[Example 2]
25-
**Input**:`haystack = "leetcode", needle = "leeto"`
18+
###[示例 2]
19+
**输入**:`haystack = "leetcode", needle = "leeto"`
2620

27-
**Output**:`-1`
21+
**输出**:`-1`
2822

29-
**Explanation**:`"leeto"did not occur in"leetcode", so we return -1.`
23+
**解释**:`"leeto"没有在"leetcode" 中出现,所以返回 -1 。`
3024

31-
###[Constraints]
25+
###[约束]
3226
-`1 <= haystack.length, needle.length <= 10000`
33-
-`haystack` and`needle` consist of only lowercase English characters.
34-
35-
##Intuition
36-
[中文题解](#中文题解)
27+
-`haystack``needle` 仅由小写英文字符组成
3728

38-
Traverse the string once, and if the`needle.length` characters after the current position are equal to`needle`, return the current`index`.
29+
##思路
30+
遍历一遍字符串,如果从当前位置起的后的`needle.length`个字符等于`needle`,则返回当前的`index`
3931

40-
##Complexity
41-
*Time:`O(m * n)`.
42-
*Space:`O(n)`.
32+
##复杂度
33+
*时间:`O(m * n)`
34+
*空间:`O(n)`
4335

4436
##Python
4537
```python
@@ -94,22 +86,3 @@ var strStr = function (haystack, needle) {
9486
```
9587
// Welcome to create a PR to complete the code of this language, thanks!
9688
```
97-
98-
##力扣“28. 找出字符串中第一个匹配项的下标”问题描述
99-
力扣链接:[28. 找出字符串中第一个匹配项的下标](https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string), 难度:**简单**
100-
101-
给你两个字符串`haystack``needle` ,请你在`haystack` 字符串中找出`needle` 字符串的第一个匹配项的下标(下标从`0` 开始)。如果`needle` 不是`haystack` 的一部分,则返回`-1`
102-
103-
###[示例 1]
104-
**输入**:`haystack = "sadbutsad", needle = "sad"`
105-
106-
**输出**:`0`
107-
108-
###[示例 1]
109-
**输入**:`haystack = "leetcode", needle = "leeto"`
110-
111-
**输出**:`-1`
112-
113-
#中文题解
114-
##思路
115-
遍历一遍字符串,如果从当前位置起的后的`needle.length`个字符等于`needle`,则返回当前的`index`

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp