23 - Edit Distance - Final DP solution in Java

Views: 1
0
0
@Rishi Srivastava Pseudo code: final int[][] dp = new int[m + 1][n + 1]; for (int i = 0; i is less than or equal to m; i++) { for (int j = 0; j is less than or equal to n; j++) { if (i == 0) { dp[i][j] = j; } else if (j == 0) { dp[i][j] = i; } else if == { dp[i][j] = dp[i-1][j-1]; } else { dp[i][j] = 1 + min(dp[i-1][j-1], dp[i][j-1], dp[i-1][j]); } } } return dp[m][n]; Time complexity: * ~ O(n^2) Space complexity: * ~ O(n^2) Github: Leetcode: