Skip to content

Commit d74384c

Browse files
committed
Runtime: 10 ms (Top 21.11%) | Memory: 42.4 MB (Top 35.11%)
1 parent 561913d commit d74384c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

scripts/algorithms/L/Longest Common Prefix/Longest Common Prefix.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 10 ms (Top 21.11%) | Memory: 42.4 MB (Top 35.11%)
12
class TrieNode{
23
TrieNode[] childs;
34
int frequency;
@@ -8,9 +9,9 @@ class TrieNode{
89
}
910

1011
class Solution {
11-
12+
1213
TrieNode root = new TrieNode();
13-
14+
1415
public String longestCommonPrefix(String[] strs) {
1516
if(strs.length == 0) return "";
1617
if(strs.length == 1) return strs[0];
@@ -19,7 +20,7 @@ public String longestCommonPrefix(String[] strs) {
1920
}
2021
return findCommonPrefix(strs[0], strs.length);
2122
}
22-
23+
2324
private void insertIntoTrie(String str) {
2425
TrieNode ptr = root;
2526
for(int i=0; i<str.length(); i++){
@@ -31,7 +32,7 @@ private void insertIntoTrie(String str) {
3132
ptr = ptr.childs[str.charAt(i)-'a'];
3233
}
3334
}
34-
35+
3536
private String findCommonPrefix(String str, int n) {
3637
String ans = "";
3738
for(int i=0; i<str.length(); i++){
@@ -43,4 +44,4 @@ private String findCommonPrefix(String str, int n) {
4344
}
4445
return ans;
4546
}
46-
}
47+
}

0 commit comments

Comments
 (0)