daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void levenshtein (String p, String q)
  2.     {
  3.         int D[][] = llenarMatriz(p.length(),q.length());
  4.         int c = 0;
  5.  
  6.         for(int a = 1; a <= p.length(); a++)
  7.         {
  8.  
  9.             for(int b = 1; b <= q.length(); b++)
  10.             {
  11.  
  12.                 if(p.charAt(a) == q.charAt(b))
  13.                 {
  14.                     c=0;
  15.                 }else{
  16.                     c=1;
  17.                 }
  18.                 D[a][b] = Math.min(Math.min(D[a][b]+c, D[a-1][b]+1), D[a][b-1]+1);
  19.             }
  20.  
  21.         }
  22.  
  23.     }
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.     public int[][] llenarMatriz(int p, int q)
  31.     {
  32.         int D[][] = new int[p][q];
  33.  
  34.         for(int a=0; a<p; a++)
  35.         {
  36.           D[a][0] = a;
  37.         }
  38.         for(int b=0; b<q; b++)
  39.         {
  40.           D[0][b] = b;
  41.         }
  42.  
  43.         return D;
  44.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top