Skip to content

Commit 504b8c8

Browse files
authored
Update LongestCommonPrefix.java
Fixed formatting
1 parent 57a8c30 commit 504b8c8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44

55
public final class LongestCommonPrefix {
66
public String longestCommonPrefix(String[] strs) {
7-
if(strs == null || strs.length == 0) return "";
7+
if (strs == null || strs.length == 0) {
8+
return "";
9+
}
810

911
Arrays.sort(strs);
1012
String shortest = strs[0];
1113
String longest = strs[strs.length - 1];
1214

1315
int index = 0;
14-
while(index < shortest.length() && index < longest.length() && shortest.charAt(index) == longest.charAt(index))
16+
while (index < shortest.length() && index < longest.length() && shortest.charAt(index) == longest.charAt(index)) {
1517
index++;
18+
}
1619

1720
return shortest.substring(0, index);
1821
}

0 commit comments

Comments
 (0)