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

Commite43ed48

Browse files
make code more concise
1 parent4f7f0bd commite43ed48

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

‎EASY/src/easy/ImplementStrStr.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,9 @@
33
publicclassImplementStrStr {
44
/**You could use substring as follows, or use two pointers to go through the haystack, if substring API call is not allowed.*/
55
publicstaticintstrStr(Stringhaystack,Stringneedle) {
6-
if(haystack ==null ||needle ==null){
7-
return -1;
8-
}
9-
if(haystack.isEmpty()){
10-
returnneedle.isEmpty() ?0 : -1;
11-
}
12-
if(needle.isEmpty()){
13-
return0;
14-
}
15-
for(inti =0;i <haystack.length() -needle.length()+1;i++){
6+
if(haystack ==null ||needle ==null ||haystack.length() <needle.length())return -1;
7+
8+
for(inti =0;i <=haystack.length() -needle.length();i++){
169
if(haystack.substring(i,i+needle.length()).equals(needle))returni;
1710
}
1811
return -1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp