public ListNode reverseIterative(ListNode list) {
    validateInput(list);

    if (list.getNext() == null) {
      return list;
    }

    ListNode head = null;
    ListNode current = list;
    while (current != null) {
      ListNode save = current;
      current = current.getNext();
      save.setNext(head);
      head = save;
    }
    return head;
  }
Iterative solution for this problem. The complexity order of this algorithm in time terms is
O(N) where N is the number of elements in the list. The complexity order in this algorithm in
space terms is O(1) because we only use two additional pointers and we don't allocate memory.
src/main/java/com/github/pedrovgs/problem22/ReverseLinkedList.java