diff --git a/0876-middle-of-the-linked-list/0876-middle-of-the-linked-list.php b/0876-middle-of-the-linked-list/0876-middle-of-the-linked-list.php new file mode 100644 index 0000000..160c227 --- /dev/null +++ b/0876-middle-of-the-linked-list/0876-middle-of-the-linked-list.php @@ -0,0 +1,32 @@ +/** + * Definition for a singly-linked list. + * class ListNode { + * public $val = 0; + * public $next = null; + * function __construct($val = 0, $next = null) { + * $this->val = $val; + * $this->next = $next; + * } + * } + */ +class Solution { + + /** + * @param ListNode $head + * @return ListNode + */ + function middleNode($head) { + $size = 0; + $navigationNode = $head; + while($navigationNode != null){ + $navigationNode = $navigationNode->next; + $size++; + } + // Dividing by 2 without round + $size = bcdiv($size, 2, 0); + for($i=0;$i<$size;$i++){ + $head = $head->next; + } + return $head; + } +} \ No newline at end of file