forked from codemistic/Data-Structures-and-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetcode1967.java
More file actions
41 lines (36 loc) · 1.09 KB
/
Leetcode1967.java
File metadata and controls
41 lines (36 loc) · 1.09 KB
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
39
40
41
package com.company;
import java.util.ArrayList;
public class Leetcode1967 {
public static void main(String[] args) {
String[] patterns = {"a","b","c"};
String word = "aaaaabbbbb";
System.out.println(numOfStrings(patterns,word));
}
// static int numOfStrings(String[] p, String word){
// int c=0;
// for (int i = 0; i <=p.length-1 ; i++) {
// int l=p[i].length();
// for (int j = 0; j <=word.length()-l ; j++) {
// StringBuilder s=new StringBuilder(word.substring(j,l));
// if((s.toString()).equals(p[i])){
// c++;
// break;
// }
//
// }
// }
// return c;
// }
public static int numOfStrings(String[] patterns, String word) {
int c=0;
for (int i = 0; i < patterns.length; i++) {
for (int j = 0; j < word.length() ; j++) {
if (word.substring(j).startsWith(patterns[i])){
c++;
break;
}
}
}
return c;
}
}