File tree 3 files changed +70
-0
lines changed
solution/0300-0399/0387.First Unique Character in a String
3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -153,6 +153,31 @@ var firstUniqChar = function (s) {
153
153
};
154
154
```
155
155
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
+
156
181
### ** ...**
157
182
158
183
```
Original file line number Diff line number Diff line change @@ -130,6 +130,31 @@ var firstUniqChar = function (s) {
130
130
};
131
131
```
132
132
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
+
133
158
### ** ...**
134
159
135
160
```
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments