Skip to content

Commit 381421d

Browse files
authored
feat: add php solution to lc problem: No.0387 (doocs#943)
No.0387.First Unique Character in a String
1 parent 51dcae7 commit 381421d

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

solution/0300-0399/0387.First Unique Character in a String/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,31 @@ var firstUniqChar = function (s) {
153153
};
154154
```
155155

156+
### **PHP**
157+
158+
```php
159+
class Solution {
160+
/**
161+
* @param String $s
162+
* @return Integer
163+
*/
164+
function firstUniqChar($s) {
165+
$hashmap = [];
166+
for ($i = 0; $i < strlen($s); $i++) {
167+
$word = $s[$i];
168+
$hasmap[$word] += 1;
169+
}
170+
for ($i = 0; $i < strlen($s); $i++) {
171+
$word = $s[$i];
172+
if ($hasmap[$word] == 1) {
173+
return $i;
174+
}
175+
}
176+
return -1;
177+
}
178+
}
179+
```
180+
156181
### **...**
157182

158183
```

solution/0300-0399/0387.First Unique Character in a String/README_EN.md

+25
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,31 @@ var firstUniqChar = function (s) {
130130
};
131131
```
132132

133+
### **PHP**
134+
135+
```php
136+
class Solution {
137+
/**
138+
* @param String $s
139+
* @return Integer
140+
*/
141+
function firstUniqChar($s) {
142+
$hashmap = [];
143+
for ($i = 0; $i < strlen($s); $i++) {
144+
$word = $s[$i];
145+
$hasmap[$word] += 1;
146+
}
147+
for ($i = 0; $i < strlen($s); $i++) {
148+
$word = $s[$i];
149+
if ($hasmap[$word] == 1) {
150+
return $i;
151+
}
152+
}
153+
return -1;
154+
}
155+
}
156+
```
157+
133158
### **...**
134159

135160
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
/**
3+
* @param String $s
4+
* @return Integer
5+
*/
6+
function firstUniqChar($s) {
7+
$hashmap = [];
8+
for ($i = 0; $i < strlen($s); $i++) {
9+
$word = $s[$i];
10+
$hasmap[$word] += 1;
11+
}
12+
for ($i = 0; $i < strlen($s); $i++) {
13+
$word = $s[$i];
14+
if ($hasmap[$word] == 1) {
15+
return $i;
16+
}
17+
}
18+
return -1;
19+
}
20+
}

0 commit comments

Comments
 (0)