Skip to content

Commit 83c7b61

Browse files
committed
문자열안의 문자 찾기
1 parent 63e9fe8 commit 83c7b61

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

StringMatchingInArray.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import java.util.*;
2+
3+
// my solution
4+
public class StringMatchingInArray {
5+
public List<String> stringMatching(String[] words) {
6+
List<String> lists = new ArrayList<>();
7+
String[] tmp = words;
8+
9+
for (int i = 0; i < words.length; i++) {
10+
for (int j = 0; j < words.length; j++) {
11+
if (tmp[i].contains(words[j]) && tmp[i] != words[j]) {
12+
if (!lists.contains(words[j]))
13+
lists.add(words[j]);
14+
}
15+
}
16+
}
17+
return lists;
18+
}
19+
}
20+
21+
/* best solution
22+
class Solution {
23+
public List<String> stringMatching(String[] words) {
24+
StringBuilder sb = new StringBuilder();
25+
for(String str : words)
26+
sb.append(" ").append(str);
27+
String allstr = sb.toString();
28+
29+
List<String> result = new LinkedList<>();
30+
for(String str : words)
31+
if(allstr.indexOf(str) != allstr.lastIndexOf(str))
32+
result.add(str);
33+
34+
return result;
35+
}
36+
}
37+
*/

0 commit comments

Comments
 (0)