Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

String Matching

Go down

String Matching Empty String Matching

Post  Admin Tue Aug 30, 2011 12:05 pm

Brute Force:

public static int match(String a, String b){
char[] cha=a.toCharArray();
char[] chb=b.toCharArray();
int m=a.length();
int n= b.length();
for(int i=0;i<n-m;i++){
for(int j=0;j<m;j++){
if(cha[i+j]!=cha[j])
continue nexti;
}
return i;
}
return -1;
}

Admin
Admin

Posts : 131
Join date : 2011-08-16

https://codefornongeek.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum