Reverse Singly linked list

Descrição

FlashCards sobre Reverse Singly linked list, criado por Suhas S em 12-02-2018.
Suhas S
FlashCards por Suhas S, atualizado more than 1 year ago
Suhas S
Criado por Suhas S quase 8 anos atrás
1
0

Resumo de Recurso

Questão Responda
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; }

Semelhante

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