String Matching

View previous topic View next topic Go down

String Matching

Post  Admin on 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

View user profile http://codefornongeek.forumotion.com

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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