File tree 6 files changed +195
-0
lines changed
0800-0899/0876.Middle of the Linked List
1200-1299/1290.Convert Binary Number in a Linked List to Integer
6 files changed +195
-0
lines changed Original file line number Diff line number Diff line change @@ -223,6 +223,43 @@ struct ListNode *middleNode(struct ListNode *head) {
223
223
}
224
224
```
225
225
226
+ ### **PHP**
227
+
228
+ ```php
229
+ /**
230
+ * Definition for a singly-linked list.
231
+ * class ListNode {
232
+ * public $val = 0;
233
+ * public $next = null;
234
+ * function __construct($val = 0, $next = null) {
235
+ * $this->val = $val;
236
+ * $this->next = $next;
237
+ * }
238
+ * }
239
+ */
240
+ class Solution {
241
+
242
+ /**
243
+ * @param ListNode $head
244
+ * @return ListNode
245
+ */
246
+ function middleNode($head) {
247
+ $count = 0;
248
+ $tmpHead = $head;
249
+ while ($tmpHead != null) {
250
+ $tmpHead = $tmpHead->next;
251
+ $count++;
252
+ }
253
+ $len = $count - floor($count / 2);
254
+ while ($count != $len) {
255
+ $head = $head->next;
256
+ $count--;
257
+ }
258
+ return $head;
259
+ }
260
+ }
261
+ ```
262
+
226
263
### ** ...**
227
264
228
265
```
Original file line number Diff line number Diff line change @@ -204,6 +204,42 @@ struct ListNode *middleNode(struct ListNode *head) {
204
204
}
205
205
```
206
206
207
+ ### **PHP**
208
+
209
+ ```php
210
+ /**
211
+ * Definition for a singly-linked list.
212
+ * class ListNode {
213
+ * public $val = 0;
214
+ * public $next = null;
215
+ * function __construct($val = 0, $next = null) {
216
+ * $this->val = $val;
217
+ * $this->next = $next;
218
+ * }
219
+ * }
220
+ */
221
+ class Solution {
222
+ /**
223
+ * @param ListNode $head
224
+ * @return ListNode
225
+ */
226
+ function middleNode($head) {
227
+ $count = 0;
228
+ $tmpHead = $head;
229
+ while ($tmpHead != null) {
230
+ $tmpHead = $tmpHead->next;
231
+ $count++;
232
+ }
233
+ $len = $count - floor($count / 2);
234
+ while ($count != $len) {
235
+ $head = $head->next;
236
+ $count--;
237
+ }
238
+ return $head;
239
+ }
240
+ }
241
+ ```
242
+
207
243
### ** ...**
208
244
209
245
```
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for a singly-linked list.
3
+ * class ListNode {
4
+ * public $val = 0;
5
+ * public $next = null;
6
+ * function __construct($val = 0, $next = null) {
7
+ * $this->val = $val;
8
+ * $this->next = $next;
9
+ * }
10
+ * }
11
+ */
12
+ class Solution {
13
+ /**
14
+ * @param ListNode $head
15
+ * @return ListNode
16
+ */
17
+ function middleNode ($head ) {
18
+ $count = 0 ;
19
+ $tmpHead = $head ;
20
+ while ($tmpHead != null ) {
21
+ $tmpHead = $tmpHead -> next ;
22
+ $count ++ ;
23
+ }
24
+ $len = $count - floor ($count / 2 );
25
+ while ($count != $len ) {
26
+ $head = $head -> next ;
27
+ $count -- ;
28
+ }
29
+ return $head ;
30
+ }
31
+ }
Original file line number Diff line number Diff line change @@ -259,6 +259,38 @@ int getDecimalValue(struct ListNode *head) {
259
259
}
260
260
```
261
261
262
+ ### **PHP**
263
+
264
+ ```PHP
265
+ /**
266
+ * Definition for a singly-linked list.
267
+ * class ListNode {
268
+ * public $val = 0;
269
+ * public $next = null;
270
+ * function __construct($val = 0, $next = null) {
271
+ * $this->val = $val;
272
+ * $this->next = $next;
273
+ * }
274
+ * }
275
+ */
276
+ class Solution {
277
+
278
+ /**
279
+ * @param ListNode $head
280
+ * @return Integer
281
+ */
282
+ function getDecimalValue($head) {
283
+ $rs = array();
284
+ while ($head != null) {
285
+ array_push($rs, $head->val);
286
+ $head = $head->next;
287
+ }
288
+ $rsStr = implode($rs);
289
+ return bindec($rsStr);
290
+ }
291
+ }
292
+ ```
293
+
262
294
### ** ...**
263
295
264
296
```
Original file line number Diff line number Diff line change @@ -225,6 +225,38 @@ int getDecimalValue(struct ListNode *head) {
225
225
}
226
226
```
227
227
228
+ ### **PHP**
229
+
230
+ ```PHP
231
+ /**
232
+ * Definition for a singly-linked list.
233
+ * class ListNode {
234
+ * public $val = 0;
235
+ * public $next = null;
236
+ * function __construct($val = 0, $next = null) {
237
+ * $this->val = $val;
238
+ * $this->next = $next;
239
+ * }
240
+ * }
241
+ */
242
+ class Solution {
243
+
244
+ /**
245
+ * @param ListNode $head
246
+ * @return Integer
247
+ */
248
+ function getDecimalValue($head) {
249
+ $rs = array();
250
+ while ($head != null) {
251
+ array_push($rs, $head->val);
252
+ $head = $head->next;
253
+ }
254
+ $rsStr = implode($rs);
255
+ return bindec($rsStr);
256
+ }
257
+ }
258
+ ```
259
+
228
260
### ** ...**
229
261
230
262
```
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for a singly-linked list.
3
+ * class ListNode {
4
+ * public $val = 0;
5
+ * public $next = null;
6
+ * function __construct($val = 0, $next = null) {
7
+ * $this->val = $val;
8
+ * $this->next = $next;
9
+ * }
10
+ * }
11
+ */
12
+ class Solution {
13
+
14
+ /**
15
+ * @param ListNode $head
16
+ * @return Integer
17
+ */
18
+ function getDecimalValue ($head ) {
19
+ $rs = array ();
20
+ while ($head != null ) {
21
+ array_push ($rs , $head -> val );
22
+ $head = $head -> next ;
23
+ }
24
+ $rsStr = implode ($rs );
25
+ return bindec ($rsStr );
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments