BJP5 Exercise 16.7: deleteBack — Help me understand the solution
问题 I have been working on this exercise to practice ListNode s, and was very frustrated because even though I thought I wrote the code correctly (as shown below), it didn't let me pass. public int deleteBack() { ListNode p = front; if(p == null) { throw new NoSuchElementException(); } if(p.next == null) { int data = p.data; p = null; return data; } while(p.next.next != null) { p = p.next; } int data = p.next.data; p.next = null; return data; } Next, I tried creating in total three new ListNode s