Skip to content

Commit 9398b85

Browse files
authored
feat: add php solution to lc problem: No.1100 (#1105)
1 parent 4806537 commit 9398b85

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

solution/1100-1199/1100.Find K-Length Substrings With No Repeated Characters/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,33 @@ function numKLenSubstrNoRepeats(s: string, k: number): number {
264264
}
265265
```
266266

267+
### **PHP**
268+
269+
```php
270+
class Solution {
271+
/**
272+
* @param String $s
273+
* @param Integer $k
274+
* @return Integer
275+
*/
276+
function numKLenSubstrNoRepeats($s, $k) {
277+
$sum = ($k * ($k + 1)) / 2 - $k;
278+
$cnt = $tmp = 0;
279+
for ($i = 0; $i < strlen($s) - $k + 1; $i++) {
280+
$str = substr($s, $i, $k);
281+
for ($j = 0; $j < $k; $j++) {
282+
$tmp += strpos($str, $str[$j]);
283+
}
284+
if ($tmp === $sum) {
285+
$cnt++;
286+
}
287+
$tmp = 0;
288+
}
289+
return $cnt;
290+
}
291+
}
292+
```
293+
267294
### **...**
268295

269296
```

solution/1100-1199/1100.Find K-Length Substrings With No Repeated Characters/README_EN.md

+27
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,33 @@ function numKLenSubstrNoRepeats(s: string, k: number): number {
243243
}
244244
```
245245

246+
### **PHP**
247+
248+
```php
249+
class Solution {
250+
/**
251+
* @param String $s
252+
* @param Integer $k
253+
* @return Integer
254+
*/
255+
function numKLenSubstrNoRepeats($s, $k) {
256+
$sum = ($k * ($k + 1)) / 2 - $k;
257+
$cnt = $tmp = 0;
258+
for ($i = 0; $i < strlen($s) - $k + 1; $i++) {
259+
$str = substr($s, $i, $k);
260+
for ($j = 0; $j < $k; $j++) {
261+
$tmp += strpos($str, $str[$j]);
262+
}
263+
if ($tmp === $sum) {
264+
$cnt++;
265+
}
266+
$tmp = 0;
267+
}
268+
return $cnt;
269+
}
270+
}
271+
```
272+
246273
### **...**
247274

248275
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
/**
3+
* @param String $s
4+
* @param Integer $k
5+
* @return Integer
6+
*/
7+
function numKLenSubstrNoRepeats($s, $k) {
8+
$sum = ($k * ($k + 1)) / 2 - $k;
9+
$cnt = $tmp = 0;
10+
for ($i = 0; $i < strlen($s) - $k + 1; $i++) {
11+
$str = substr($s, $i, $k);
12+
for ($j = 0; $j < $k; $j++) {
13+
$tmp += strpos($str, $str[$j]);
14+
}
15+
if ($tmp === $sum) {
16+
$cnt++;
17+
}
18+
$tmp = 0;
19+
}
20+
return $cnt;
21+
}
22+
}

0 commit comments

Comments
 (0)