Skip to content

Commit 06137e3

Browse files
author
Mrinal Chauhan
committed
Longest Common Prefix
1 parent 7b127ec commit 06137e3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/java/com/thealgorithms/strings/LongestCommonPrefix.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
package com.thealgorithms.strings;
22
import java.util.*;
3-
//To find the longest Common Prefix of String array
4-
public class longestCommonPrefix {
3+
// To find the longest Common Prefix of String array
4+
// geeksforgeeks explaination: https://www.geeksforgeeks.org/longest-common-prefix-using-sorting/
5+
6+
/* The Longest Common Prefix (LCP) of a set of strings is the longest substring that appears at the beginning of each of the strings in the set. For example, given the strings:
7+
"flower"
8+
"flow"
9+
"flight"
10+
The longest common prefix is "fl", as it is the longest substring that is common at the start of all three strings. */
11+
public class LongestCommonPrefix {
512
public static String longestPrefix(String[] str){
613
int n=str.length;
714
Arrays.sort(str);

0 commit comments

Comments
 (0)