Has to be O(n) and in-place (space complexity of 1). The code below does work, but is there a simpler or better way?
public void invert() { if (this.getH
How about this:
public void invert() { if (head != null) { for (Node tail = head.getNext(); tail != null; ) { Node nextTail = tail.getNext(); tail.setNext(head); head = tail; tail = nextTail; } } }