Reverse Singly linked list

Beschreibung

Karteikarten am Reverse Singly linked list, erstellt von Suhas S am 12/02/2018.
Suhas S
Karteikarten von Suhas S, aktualisiert more than 1 year ago
Suhas S
Erstellt von Suhas S vor fast 8 Jahre
1
0

Zusammenfassung der Ressource

Frage Antworten
Reverse a singly linked list iterative solution /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public ListNode reverseList(ListNode head) { if(head == null) return head; ListNode cur = head; ListNode prev = null; ListNode next; while(cur != null){ next = cur.next; cur.next = prev; prev = cur; cur = next; } return prev; } }
Reverse singly linked list using recursion puclic void ReverseList(ListNode p){ if(p== null) return p; ReverseList(p.next); ListNode q = p.next; q.next = p; p.next = null; }
Zusammenfassung anzeigen Zusammenfassung ausblenden

ähnlicher Inhalt

HW 2_1
Kevin Magno
Remove Duplicates from a Linked List
Suhas S