Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
2 changes: 1 addition & 1 deletion 2 DataStructures/Graphs/FloydWarshall.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public FloydWarshall(int numberofvertices) {
[numberofvertices
+ 1]; // stores the value of distance from all the possible path form the source
// vertex to destination vertex
Arrays.fill(DistanceMatrix, 0);
// here the distanceMatrix is initialized by 0s b default upon initialization with new keyword

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, thanks for considering this 👍

this.numberofvertices = numberofvertices;
}

Expand Down
27 changes: 27 additions & 0 deletions 27 DynamicProgramming/LongestCommonSubstring.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class LongestCommonSubstring {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add problem statement and other relevant info.


public static String string1, string2;
public static int[][] dp;
public static void main(String[] args) {
int res = 0;
string1 = "abbaf";
string2 = "abcdef";
int n = string1.length();
int m = string2.length();
dp = new int[n+1][m+1];
for(int i = 0;i <= n;i++) {
dp[0][i] = 0;
dp[i][0] = 0;
}

for(int i = 1;i <= n;i++) {
for(int j = 1;j <= m;j++) {
if(string1.charAt(i-1) == string2.charAt(j-1)) {
dp[i][j] = 1 + dp[i-1][j-1];
res = Math.max(res, dp[i][j]);
}else dp[i][j] = 0;
}
}
System.out.println(res);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.