Sunday, 18 August 2013

Need output as to if somewhere within the first array consists second array

Need output as to if somewhere within the first array consists second array

public boolean contains(int[] a,int[] b) {
int w=0;
for(int i=0;i<a.length && w<b.length;i++) {
if(a[i]==b[w])
w++;
else w=0;
}
System.out.println(w);
if(w==b.length) return true;
else return false;
}



This code is failing for the scenario-contains({1, 2, 1, 2, 3}, {1, 2,
3})-for obvious reasons. However, i can't put the right code in that
amends the right output. Please help me out.

No comments:

Post a Comment