@@ -92,6 +92,67 @@ console.log (smallestSubstr ("x", ['x']));
9292console .log (smallestSubstr (" afekbtcodebancfeger" , [" a" ," b" ," c" ]));
9393```
9494
95+ ## Java Implementation
96+
97+ ### [ Solution] ( ./Java/minSubstring.java )
98+
99+ ``` java
100+ /**
101+ * @date 01/01/19
102+ * @author SPREEHA DUTTA
103+ */
104+ import java.util.* ;
105+ public class minSubstring {
106+
107+ public static boolean check (String s ,char []c )
108+ {
109+ String str= new String (c);int k= 0 ;
110+ for (int i= 0 ;i< c. length;i++ )
111+ {
112+ if (s. contains(str. substring(i,i+ 1 )))
113+ k++ ;
114+ }
115+ if (k== c. length)
116+ return true ;
117+ else
118+ return false ;
119+ }
120+
121+ public static void generate (String str ,char c []) {
122+ String s;int min;
123+ min= str. length();String s1= " " ;
124+ for (int i= 0 ;i<= str. length()- 1 ;i++ )
125+ {
126+ for (int j= i+ 1 ;j<= str. length();j++ )
127+ {
128+ s= str. substring(i,j);
129+ if (check(s,c)== true )
130+ {
131+ if (min>= s. length())
132+ {
133+ min= s. length();
134+ s1= s;
135+ }
136+ }
137+ }
138+ }
139+ System . out. println(s1);
140+ }
141+
142+ public static void main (String [] args ) {
143+ Scanner sc= new Scanner (System . in);
144+ String s;int i,n;
145+ System . out. println(" Enter a string" );
146+ s= sc. next();
147+ System . out. println(" Enter size of character array" );
148+ n= sc. nextInt();
149+ char a[]= new char [n];
150+ for (i= 0 ;i< n;i++ )
151+ a[i]= sc. next(). charAt(0 );
152+ generate(s,a);
153+ }
154+ }
155+ ```
95156
96157## C++Implementation
97158
@@ -170,9 +231,6 @@ int main() {
170231}
171232```
172233
173-
174-
175-
176234### Have Another solution?
177235
178236The beauty of programming lies in the fact that there is never a single solution to any problem.
0 commit comments