Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
arranged comments
  • Loading branch information
BrajBliss authored Apr 9, 2022
commit 60f51624a07b651e42abc36d94618eabf0f30bc8
6 changes: 4 additions & 2 deletions java/19-Remove-Nth-Node-From-End-of-List.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {

// Using Two Pointer Approach:
// Take a pointer second and put it at (n+1)th position from the beginning
// Take pointer first and move it forward till second reaches Last Node and second.next points to null
// At that point we would have reached the (n-1)th node from the end using the pointer first
// Unlink or Skip that node


class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {

if (head == null || head.next == null) return null;

ListNode temp = new ListNode(0);
Expand Down