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

Sign up
Appearance settings

Commit 4edd350

Browse files
committed
Time: 9 ms (46.92%), Space: 18.9 MB (93.70%) - LeetHub
1 parent c750215 commit 4edd350

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
3+
/**
4+
* @param String[] $strs
5+
* @return String
6+
*/
7+
function longestCommonPrefix($strs) {
8+
9+
$prefix = '';
10+
11+
for ($i=0; $i<strlen($strs[0]); $i++)
12+
{
13+
$prefix .= $strs[0][$i];
14+
foreach($strs as $str)
15+
{
16+
if (substr($str, 0, strlen($prefix)) == $prefix)
17+
{
18+
continue;
19+
}
20+
else
21+
{
22+
return substr($prefix, 0, -1);
23+
}
24+
}
25+
}
26+
return $prefix;
27+
}
28+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /