Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void levenshtein (String p, String q)
- {
- int D[][] = llenarMatriz(p.length(),q.length());
- int c = 0;
- for(int a = 1; a <= p.length(); a++)
- {
- for(int b = 1; b <= q.length(); b++)
- {
- if(p.charAt(a) == q.charAt(b))
- {
- c=0;
- }else{
- c=1;
- }
- D[a][b] = Math.min(Math.min(D[a][b]+c, D[a-1][b]+1), D[a][b-1]+1);
- }
- }
- }
- public int[][] llenarMatriz(int p, int q)
- {
- int D[][] = new int[p][q];
- for(int a=0; a<p; a++)
- {
- D[a][0] = a;
- }
- for(int b=0; b<q; b++)
- {
- D[0][b] = b;
- }
- return D;
- }
Add Comment
Please, Sign In to add comment