FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/algorithms/java/src/strStr/strStr.java at master · wcoder0/leetcode · GitHub
wcoder0
leetcode
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
algorithms
/
java
/
src
/
strStr
/
strStr.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
38 lines (35 loc) · 1.07 KB
Breadcrumbs
leetcode
/
algorithms
/
java
/
src
/
strStr
/
strStr.java
Copy path
File metadata and controls
38 lines (35 loc) · 1.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Source : https://oj.leetcode.com/problems/implement-strstr/
// Inspired by : http://www.jiuzhang.com/solutions/implement-strstr/
// Author : Lei Cao
// Date : 2015-10-02
/**********************************************************************************
*
* Implement strStr().
*
* Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.
*
*
**********************************************************************************/
package
strStr
;
/**
* Created by leicao on 2/10/15.
*/
public
class
strStr
{
public
int
strStr
(
String
haystack
,
String
needle
) {
if
(
haystack
==
null
||
needle
==
null
) {
return
-
1
;
}
int
i
,
j
=
0
;
for
(
i
=
0
;
i
<
haystack
.
length
() -
needle
.
length
() +
1
;
i
++) {
for
(
j
=
0
;
j
<
needle
.
length
();
j
++) {
if
(
haystack
.
charAt
(
i
+
j
) !=
needle
.
charAt
(
j
)) {
break
;
}
}
if
(
j
==
needle
.
length
()) {
return
i
;
}
}
return
-
1
;
}
}
Back
|
FazBrowse Home
|
New Git URL