int (@NotNull CharSequence str1, @NotNull CharSequence str2, boolean caseSensitive) { // Wagner-Fischer implementation of Levenshtein distance // (http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm) int[][] d = prepare(str1.length(), str2.length()); for (int i = 1; i <= str1.length(); i++) { for (int j = 1; j <= str2.length(); j++) { int cost = equal(str1.charAt(i - 1), str2.charAt(j - 1), caseSensitive) ? 0 : 1; d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost); } } return d[str1.length()][str2.length()]; }