Introducción

1

¿Ya tomaste el Curso Avanzado de Algoritmos: Patrones de Arrays y Strings?

Lista Enlazada

2

Estructura de datos: Lista Enlazada

3

Programando listas enlazadas con Java

4

Cómo Invertir una Lista Enlazada

5

Odd Even Linked List: análisis del problema

6

Solución de Odd Even Linked List

7

Playground: Odd Even Liked List

8

Programando Odd Even Linked List con C++

9

Linked List Cycle: análisis del problema

10

Solución de Linked List Cycle

11

Playground: Linked List Cycle

12

Programando Linked List Cycle con Python

13

Palindrome Linked List: análisis del problema

14

Solución de Palindrome Linked List

15

Playground: Palindrome Linked List

16

Programando Palindrome Linked List con Java

17

Reorder List: análisis del problema

18

Solución de Reorder List

19

Programando Reorder List con JavaScript

20

Playground: Reorder List Without Repeated Values

21

Reto: LRU Caché

22

Ejercicios Prácticos con Listas Enlazadas y Historial de Navegador

23

Operaciones con Listas Enlazadas: Suma, Intercambio y Navegador

Pilas y colas

24

Estructura de datos: Pilas y Colas

25

Paréntesis Válido: análisis del problema

26

Solución de Paréntesis Válido

27

Playground: Paréntesis Válido

28

Programando Paréntesis Válido con C++

29

Comparación de Cadenas con Backspaces

Colas de prioridad

30

Estructura de datos: Colas de Prioridad

31

K Closest Points to Origin: análisis del problema

32

Solución de K Closest Points to Origin

33

Playground: K Closest Points to Origin

34

Programando K Closest Points to Origin con Python

35

Reorganize String: análisis del problema

36

Solución de Reorganize String

37

Playground: Reorganize String

38

Programando Reorganize String con Python

39

Colas de Prioridad: Ejercicios Prácticos y Soluciones

40

Colas de Prioridad y Gestión de Eventos

Próximos pasos

41

Toma el Curso Avanzado de Algoritmos: Grafos y Árboles

No tienes acceso a esta clase

¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera

Odd Even Linked List: análisis del problema

5/41
Recursos

Aportes 4

Preguntas 0

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad?

  • Como borrador, el análisis de si el curren_node es par, haga el cambio con el next, pero también que el nuevo current ya no sea 2 sino 4 y para el 5 si el previous es par, que sería 2 entonces cámbielo.
    Es un borrador de 25m 🙆‍♂️
Hecho en TypeScript (la primera parte la conseguí en leetcode): ``` class ListNode { val: number; next: ListNode | null; constructor(val?: number, next?: ListNode | null) { *this*.val = val === undefined ? 0 : val; *this*.next = next === undefined ? null : next; }} function oddEvenList(head: ListNode | null): ListNode | null { if (!head) { return null; } let odd = head let even = head.next let evenHead = even while (even !== null && even.next !== null) { odd.next = odd.next!.next; odd = odd.next!; even.next = even.next.next; even = even.next; } odd.next = evenHead return head;} const listNode: ListNode = new ListNode(1, new ListNode(2, new ListNode(3, new ListNode(4, new ListNode(5)))));/\* input \[1,2,3,4,5] o-e-o-e-o output \[1,3,5,2,4] o-o-o-e-e\*/ const listNode2: ListNode = new ListNode(2, new ListNode(1, new ListNode(3, new ListNode(5, new ListNode(6, new ListNode(4, new ListNode(7)))))));/\* input \[2,1,3,5,6,4,7] o-e-o-e-o-e-o output \[2,3,6,7,1,5,4] o-o-o-o-e-e-e\*/ console.log(oddEvenList(listNode));console.log(oddEvenList(listNode2)); ```
En ruby xD ```js class LinkedList attr_accessor :head, :tail def initialize @head = nil @tail = nil end def append(node) return if node.nil? if @head.nil? @head = node @tail = node else @tail.next = node @tail = node end end def to_a result = [] current = @head while current result << current.value current = current.next end result end end class Node attr_accessor :value, :next def initialize(value) @value = value @next = nil end end def next_node_of_next_node(node) return if node.next.nil? node.next.next end def disconnect_node(node) return if node.nil? Node.new(node.value) end def alternate_linked_list(node) alternated = LinkedList.new new_node = node while new_node alternated.append(disconnect_node(new_node)) new_node = next_node_of_next_node(new_node) end alternated end def odd_even_linked_list(linked_list) response_linked_list = alternate_linked_list(linked_list.head) response_linked_list.tail.next = alternate_linked_list(linked_list.head.next).head response_linked_list end ```class LinkedList attr\_accessor :head, :tail def initialize @head = nil @tail = nil end def append(node) return if node.nil? if @head.nil? @head = node @tail = node else @tail.next = node @tail = node end end def to\_a result = \[] current = @head while current result << current.value current = current.next end result endend class Node attr\_accessor :value, :next def initialize(value) @value = value @next = nil endend def next\_node\_of\_next\_node(node) return if node.next.nil? node.next.nextend def disconnect\_node(node) return if node.nil? Node.new(node.value)end def alternate\_linked\_list(node) alternated = LinkedList.new new\_node = node while new\_node alternated.append(disconnect\_node(new\_node)) new\_node = next\_node\_of\_next\_node(new\_node) end alternatedend def odd\_even\_linked\_list(linked\_list) response\_linked\_list = alternate\_linked\_list(linked\_list.head) response\_linked\_list.tail.next = alternate\_linked\_list(linked\_list.head.next).head response\_linked\_listend

Esta es mi solución en Java: