Submission Detail

124 / 124 test cases passed.
Status:

Accepted

Runtime: 156 ms
Memory Usage: 45.1 MB
Submitted: 1 week, 3 days ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

0
2
4
6
8
10
12
14
16
18
20
10
20
30
40
50
java
Runtime (ms)
Distribution (%)

0
2
4
6
8
10
12
14
16
18
20
20
40
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

40000
40500
41000
41500
42000
42500
43000
2
4
6
8
10
12
java
Memory (KB)
Distribution (%)

40000
40500
41000
41500
42000
42500
43000
5
10
Zoom area by dragging across this chart

Invite friends to challenge Longest Common Prefix


Submitted Code: 1 week, 3 days ago

Language: java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Solution {
public String longestCommonPrefix(String[] strs) {
if (strs.length < 1)
return "";
if (strs.length == 1)
return strs[0];
boolean same = true;
String prefix = "";
String p = "";
int index = 0;
while (same) {
if (strs[0].equals(""))
return "";
if (index < strs[0].length()) {
prefix = prefix + strs[0].charAt(index++);
} else {
return prefix;
}
System.out.println("Concatenated. " + prefix);
for (int i = 0; i < strs.length; i++) {
if (prefix.length() <= strs[i].length()) {
System.out.println("i = " + i + " " + strs[i].substring(0,prefix.length()));
if (strs[i].substring(0,prefix.length()).equals(prefix)) {
System.out.println(i + " Match.");
continue;
} else {
same = false;
System.out.println("False match.");
p = prefix.substring(0,prefix.length()-1);
System.out.println("Returning " + p);
return p;
}
} else {
p = prefix.substring(0,prefix.length()-1);
System.out.println("Returning " + p);
return p;
}
}
}
System.out.println(p);
return p;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX