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 71d0c04

Browse files
Update 0014-longest-common-prefix.php
1 parent 4792b42 commit 71d0c04

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

‎0014-longest-common-prefix/0014-longest-common-prefix.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ class Solution {
88
*/
99
function longestCommonPrefix($strs) {
1010

11-
$prefix = '';
11+
$common = '';
1212

1313
for ($i=0; $i<strlen($strs[0]); $i++)
1414
{
15-
$prefix .= $strs[0][$i];
15+
$common .= $strs[0][$i];
1616
foreach($strs as $str)
1717
{
18-
if (substr($str, 0, strlen($prefix)) == $prefix)
18+
if (substr($str, 0, strlen($common)) == $common)
1919
{
2020
continue;
2121
}
2222
else
2323
{
24-
return substr($prefix, 0, -1);
24+
return substr($common, 0, -1);
2525
}
2626
}
2727
}
28-
return $prefix;
28+
return $common;
2929
}
3030
}

0 commit comments

Comments
(0)

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