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 211740e

Browse files
authored
feat: add php solution to lc problem: No.0014 (#965)
1 parent 2a20e90 commit 211740e

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

‎solution/0000-0099/0014.Longest Common Prefix/README.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,27 @@ impl Solution {
229229
}
230230
```
231231

232+
### **PHP**
233+
234+
```php
235+
class Solution {
236+
/**
237+
* @param String[] $strs
238+
* @return String
239+
*/
240+
function longestCommonPrefix($strs) {
241+
$rs = "";
242+
for ($i = 0; $i < strlen($strs[0]); $i++) {
243+
for ($j = 1; $j < count($strs); $j++) {
244+
if ($strs[0][$i] != $strs[$j][$i]) return $rs;
245+
}
246+
$rs = $rs.$strs[0][$i];
247+
}
248+
return $rs;
249+
}
250+
}
251+
```
252+
232253
### **...**
233254

234255
```

‎solution/0000-0099/0014.Longest Common Prefix/README_EN.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,27 @@ impl Solution {
220220
}
221221
```
222222

223+
### **PHP**
224+
225+
```php
226+
class Solution {
227+
/**
228+
* @param String[] $strs
229+
* @return String
230+
*/
231+
function longestCommonPrefix($strs) {
232+
$rs = "";
233+
for ($i = 0; $i < strlen($strs[0]); $i++) {
234+
for ($j = 1; $j < count($strs); $j++) {
235+
if ($strs[0][$i] != $strs[$j][$i]) return $rs;
236+
}
237+
$rs = $rs.$strs[0][$i];
238+
}
239+
return $rs;
240+
}
241+
}
242+
```
243+
223244
### **...**
224245

225246
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
/**
3+
* @param String[] $strs
4+
* @return String
5+
*/
6+
function longestCommonPrefix($strs) {
7+
$rs = "";
8+
for ($i = 0; $i < strlen($strs[0]); $i++) {
9+
for ($j = 1; $j < count($strs); $j++) {
10+
if ($strs[0][$i] != $strs[$j][$i]) return $rs;
11+
}
12+
$rs = $rs.$strs[0][$i];
13+
}
14+
return $rs;
15+
}
16+
}

0 commit comments

Comments
(0)

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