Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active August 21, 2020 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/afdc1bbc02cec415ad18d830d9143549 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/afdc1bbc02cec415ad18d830d9143549 to your computer and use it in GitHub Desktop.
Just PHP FUN 082.

Just PHP FUN 082.

Started at 22:54 21.08.2020 Aug Friday.
Finished at 22:56 21.08.2020 Aug Saturday. (0hrs 02minutes)

Gotcha!  Remember, when parsing the linked list from the string, the $data in each node must be **non-negative integers**!
Failed asserting that false is true.
<?php
# https://www.codewars.com/kata/582c5382f000e535100001a7 Parse a linked list from a string.
function parse(string $string) {
if("NULL" === $string) return NULL;
$array = explode(" -> ",$string);
$head = new Node(abs($array[0]));
$node = $head;
for($i = 1; $i < count($array) - 1; $i+=1){
$node->next = new Node(abs($array[$i]));
$node = $node->next;
}
return $head;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment