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

Commit88dd08f

Browse files
committed
docs: 完全同步第28题英文版到 leetcoder.net 的原始内容
1 parent71d313d commit88dd08f

File tree

1 file changed

+5
-36
lines changed

1 file changed

+5
-36
lines changed

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

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,8 @@ The first occurrence is at index 0, so we return 0.
4747
classSolution:
4848
defstrStr(self,haystack:str,needle:str) ->int:
4949
for iinrange(len(haystack)):
50-
j=0
51-
52-
while i+ j<len(haystack)and haystack[i+ j]== needle[j]:
53-
j+=1
54-
55-
if j==len(needle):
56-
return i
50+
if haystack[i:i+len(needle)]== needle:
51+
return i
5752

5853
return-1
5954
```
@@ -62,14 +57,8 @@ class Solution:
6257
```javascript
6358
varstrStr=function (haystack,needle) {
6459
for (let i=0; i<haystack.length; i++) {
65-
let j=0
66-
67-
while (i+ j<haystack.length&& haystack[i+ j]== needle[j]) {
68-
j+=1
69-
70-
if (j==needle.length) {
71-
return i
72-
}
60+
if (haystack.slice(i, i+needle.length)== needle) {
61+
return i
7362
}
7463
}
7564

@@ -102,27 +91,7 @@ var strStr = function (haystack, needle) {
10291
# Welcome to create a PR to complete the code of this language, thanks!
10392
```
10493

105-
##C
106-
```c
107-
// Welcome to create a PR to complete the code of this language, thanks!
108-
```
109-
110-
##Kotlin
111-
```kotlin
112-
// Welcome to create a PR to complete the code of this language, thanks!
113-
```
114-
115-
##Swift
116-
```swift
117-
// Welcome to create a PR to complete the code of this language, thanks!
118-
```
119-
120-
##Rust
121-
```rust
122-
// Welcome to create a PR to complete the code of this language, thanks!
123-
```
124-
125-
##Other languages
94+
##C, Kotlin, Swift, Rust or other languages
12695
```
12796
// Welcome to create a PR to complete the code of this language, thanks!
12897
```

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp