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

Programación de un Historial de Navegador en Java

23

Algoritmos de Búsqueda: Binaria y Lineal

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

Manipulación de colas de prioridad en estructuras de datos Python

40

Resolviendo Sudokus con Backtracking

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

Playground: Palindrome Linked List

15/41

Aportes 6

Preguntas 0

Ordenar por:

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

My Solution!! ![](https://static.platzi.com/media/user_upload/image-10294a5c-4d69-4deb-b6ba-efa85208fb3b.jpg)
Mi solución:class Nodo {    constructor(valor) {      this.valor = valor;      this.siguiente = null;    }  }  function isPalindrome(head) {    // Tu código aquí 👇    let slow = head, fast = head;    let leftHalf = \[slow.valor];    let rightHalf = \[];     while (fast.siguiente && fast.siguiente.siguiente) {        fast = fast.siguiente.siguiente;        slow = slow.siguiente;        leftHalf.push(slow.valor);    }     while (slow.siguiente) {        rightHalf.push(slow.siguiente.valor);        slow = slow.siguiente;    }     rightHalf.reverse();     const minLength = Math.min(leftHalf.length, rightHalf.length);     for (let index = 0; index < minLength; index++) {        if (leftHalf\[index] !== rightHalf\[index]) return false;     }     return true;} function clon(obj) {    return JSON.parse(JSON.stringify(obj));} // Inputconst nodo1 = new Nodo("a");const nodo2 = new Nodo("b");const nodo3 = new Nodo("a");nodo1.siguiente = nodo2;nodo2.siguiente = nodo3; console.log(isPalindrome(nodo1)); ```js class Nodo { constructor(valor) { this.valor = valor; this.siguiente = null; } } function isPalindrome(head) { // Tu código aquí 👇 let slow = head, fast = head; let leftHalf = [slow.valor]; let rightHalf = []; while (fast.siguiente && fast.siguiente.siguiente) { fast = fast.siguiente.siguiente; slow = slow.siguiente; leftHalf.push(slow.valor); } while (slow.siguiente) { rightHalf.push(slow.siguiente.valor); slow = slow.siguiente; } rightHalf.reverse(); const minLength = Math.min(leftHalf.length, rightHalf.length); for (let index = 0; index < minLength; index++) { if (leftHalf[index] !== rightHalf[index]) return false; } return true; } function clon(obj) { return JSON.parse(JSON.stringify(obj)); } // Input const nodo1 = new Nodo("a"); const nodo2 = new Nodo("b"); const nodo3 = new Nodo("a"); nodo1.siguiente = nodo2; nodo2.siguiente = nodo3; console.log(isPalindrome(nodo1)); ```
mi solución: ``` export function isPalindrome(cabeza) { if (!cabeza || !cabeza.siguiente) return true; var slow = cabeza; var fast = cabeza; while (fast !== null && fast.siguiente !== null) { slow = slow.siguiente; fast = fast.siguiente.siguiente; } var prev = null; var current = slow; //\* reversing the second half of the list while (current !== null) { var siguienteNode = current.siguiente; current.siguiente = prev; prev = current; current = siguienteNode; } var firstHalf = cabeza; var secondHalf = prev; while (secondHalf !== null) { if (firstHalf.valor !== secondHalf.valor) { return false; } firstHalf = firstHalf.siguiente; secondHalf = secondHalf.siguiente; } return true;} ```
Mi solución: ![](https://static.platzi.com/media/user_upload/image-81713d2e-a418-4c42-9326-e5210f55868d.jpg)

En Python no fue necesario clonar, a una variable se le asigna la cabeza

def isPalindrome(cabeza):
    if not cabeza: return True
    p1 = cabeza
    p2 = reversarLista(encontrarMitad(p1))
    esPalindromo = True
    while esPalindromo and p2:
        if p1.valor != p2.valor:
            esPalindromo = False
        p1 = p1.siguiente
        p2 = p2.siguiente
    return esPalindromo
undefined