LEETCODE 234 (JAVASCRIPT) | PALINDROME LINKED LIST

Поділитися
Вставка
  • Опубліковано 9 січ 2025

КОМЕНТАРІ •

  • @sahankodagi2963
    @sahankodagi2963 2 роки тому +3

    It's kind of insane that such high quality information is completely free.
    Thanks a lot man, you are changing lives.

  • @edetmmekut809
    @edetmmekut809 Рік тому +1

    Thanks @Andy Gala ,but pls why is this consider easy?

  • @lewisnt_
    @lewisnt_ 3 роки тому +1

    your white board illustrations are a very nice addition

  • @sourenasahraian2055
    @sourenasahraian2055 2 роки тому +2

    Just a quick note that may trip people up , line 42 the mid name might be a bit of misnomer, the reverse will return the previous which is the very end of the linkedlist to the right . We are really comparing the very end to the very beginning of linkedlist in the first iteration.

    • @aallxxmf
      @aallxxmf 2 місяці тому

      and also, len is a little bit misleading, because len is only half the lenght of the arr, which is used to compare the reversed and the original only to the half of the linked list

  • @danielbilic702
    @danielbilic702 2 роки тому +1

    Hey really nice video :) Thanks for thath. Just a small nit. There is no need for the len variable. Since we reverse the second half of the linked list we can just call while(mid) on the second while loop cuz mid will point to null eventually.
    /**
    * Definition for singly-linked list.
    * function ListNode(val, next) {
    * this.val = (val===undefined ? 0 : val)
    * this.next = (next===undefined ? null : next)
    * }
    */
    /**
    * @param {ListNode} head
    * @return {boolean}
    */
    const reverseList = head =>{
    let cur = head;
    let prev = null;
    let next = null;
    while(cur){
    next = cur.next;
    cur.next = prev;
    prev = cur;
    cur = next;
    }
    return prev;
    }
    var isPalindrome = function(head) {
    let slow = head;
    let fast = head;
    // fast.next cuz we use fast.next.next and that would return an error if fast.next is null
    while(fast && fast.next){
    fast = fast.next.next;
    slow = slow.next;
    }
    let mid = reverseList(slow);
    let pointer = head;
    while(mid){
    if(mid.val !== pointer.val){
    return false
    }
    mid = mid.next;
    pointer = pointer.next;
    }
    return true;
    };

  • @marineoceania
    @marineoceania 2 роки тому

    Thanks for this awesome video; and all the other videos! This helps me so much.

  • @cesaro60
    @cesaro60 2 роки тому

    Amazingly explained. Thanks for sharing!

  • @misha_yt5419
    @misha_yt5419 Місяць тому

    Great video!!!

  • @Olayiwolaibrahim-rh2rh
    @Olayiwolaibrahim-rh2rh Місяць тому

    how can leetcode regard this as easy

  • @seth_king_codes
    @seth_king_codes 2 роки тому

    another vid of gold