static int levenWithSwapsSubstringIC(S haystack, S needle) { int m = strL(needle), n = strL(haystack); // base cases if (containsIgnoreCase(haystack, needle)) ret 0; int[] vx = new int[n+1], v0 = new int[n+1], v1 = new int[n+1]; for i to m: { // iterate over needle v1[0] = i+1; for j to n: { // iterate over haystack int cost = neqic(needle.charAt(i), haystack.charAt(j)) ? 1 : 0; int d = min3(v1[j]+1, // insertion v0[j+1]+1, // deletion v0[j]+cost); // substitution if (i > 0 && j > 0 && equalsIgnoreCase(needle.charAt(i), haystack.charAt(j-1)) && equalsIgnoreCase(needle.charAt(i-1), haystack.charAt(j))) d = min(d, vx[j-1] + 1); // transposition v1[j+1] = d; } int[] temp = vx; vx = v0; v0 = v1; v1 = temp; } ret minOfIntArray(v0); }