LinkedLists.FakeNode

To avoid border cases we can create a fake or how it is called sentinel node

public void DoSmth(ListNode head) {
  ListNode fakeNode = new ListNode();
  fakeNode.next = head;

  while (fakeNode.next.next != null) {
    // do smth...
    fakeNode = fakeNode.Next;
  }
  return fakeNode.next; 
}
This entry was posted in Без рубрики. Bookmark the permalink.