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
public void invert() { if (first == null) return; Node prev = null; for ( Node next = first.next; next != null; next = first.next) { first.next = prev; prev = first; first = next; } first.next = prev; }