Skip to content

Commit 41d5f60

Browse files
authored
feat: add php solution to lc problem: No.0058 (doocs#907)
No.0058.Length of Last Word
1 parent 9a7c8ed commit 41d5f60

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

solution/0000-0099/0058.Length of Last Word/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,28 @@ impl Solution {
176176
}
177177
```
178178

179+
### **PHP**
180+
181+
```php
182+
class Solution {
183+
/**
184+
* @param String $s
185+
* @return Integer
186+
*/
187+
function lengthOfLastWord($s) {
188+
$count = 0;
189+
while ($s[strlen($s) - 1] == " ") {
190+
$s = substr($s, 0, -1);
191+
}
192+
while (strlen($s) != 0 && $s[strlen($s) - 1] != " ") {
193+
$count++;
194+
$s = substr($s, 0, -1);
195+
}
196+
return $count;
197+
}
198+
}
199+
```
200+
179201
### **...**
180202

181203
```

solution/0000-0099/0058.Length of Last Word/README_EN.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,28 @@ impl Solution {
160160
}
161161
```
162162

163+
### **PHP**
164+
165+
```php
166+
class Solution {
167+
/**
168+
* @param String $s
169+
* @return Integer
170+
*/
171+
function lengthOfLastWord($s) {
172+
$count = 0;
173+
while ($s[strlen($s) - 1] == " ") {
174+
$s = substr($s, 0, -1);
175+
}
176+
while (strlen($s) != 0 && $s[strlen($s) - 1] != " ") {
177+
$count++;
178+
$s = substr($s, 0, -1);
179+
}
180+
return $count;
181+
}
182+
}
183+
```
184+
163185
### **...**
164186

165187
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
/**
3+
* @param String $s
4+
* @return Integer
5+
*/
6+
function lengthOfLastWord($s) {
7+
$count = 0;
8+
while ($s[strlen($s) - 1] == " ") {
9+
$s = substr($s, 0, -1);
10+
}
11+
while (strlen($s) != 0 && $s[strlen($s) - 1] != " ") {
12+
$count++;
13+
$s = substr($s, 0, -1);
14+
}
15+
return $count;
16+
}
17+
}

0 commit comments

Comments
 (0)