Valid Anagram - LeetCode 242 - JavaScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ม.ค. 2025

ความคิดเห็น • 15

  • @willbdev
    @willbdev 9 หลายเดือนก่อน +1

    Dude this was kicking my ass recently. Your way of explaining made it click... Thank you.

    • @AlgoJS
      @AlgoJS  9 หลายเดือนก่อน

      Awesome! Glad it helped!

  • @junbaek0307
    @junbaek0307 ปีที่แล้ว

    I just wanted to say your videos are PURE GOLD. From a students perspective, these step by step walk throughs are super helpful and you explain it so much better than teachers/professors!

    • @AlgoJS
      @AlgoJS  ปีที่แล้ว

      Thank you!

  • @mikelodeon_
    @mikelodeon_ 2 หลายเดือนก่อน

    This was so clear to understand, thanks!

  • @zonico5826
    @zonico5826 ปีที่แล้ว

    Hot takes also include assigning the first 26 primes uniquely to each Letter, mapping the Words to the corresponding primes and comparing each accumulated products

  • @misha_yt5419
    @misha_yt5419 3 หลายเดือนก่อน

    Thank you!

  • @zuberkhan2668
    @zuberkhan2668 2 ปีที่แล้ว +1

    very helpful

  • @levyroth
    @levyroth ปีที่แล้ว

    Simply sort the characters in a string, a to z, and join to create a new word. If the word is the same for both strings it's an anagram. Much simpler to understand.

    • @AlgoJS
      @AlgoJS  ปีที่แล้ว +1

      Definitely a simpler approach but in terms of time complexity, sorting the characters of both strings and joining will be greater than if we used a frequency map to solve the problem.

  • @amotekundev
    @amotekundev ปีที่แล้ว

    Thank you

  • @suheybhersi5501
    @suheybhersi5501 2 ปีที่แล้ว

    Goated

  • @abbesatty9498
    @abbesatty9498 ปีที่แล้ว

    Your short video was so clear than this one, helpful content nevertheless.

    • @AlgoJS
      @AlgoJS  ปีที่แล้ว

      Will be improving production and explanation in new vids!

  • @NadidLinchestein
    @NadidLinchestein 5 หลายเดือนก่อน

    My Solution
    /**
    * @param {string} s
    * @param {string} t
    * @return {boolean}
    */
    var isAnagram = function(s, t) {
    if (s.length !== t.length) {
    return false;
    }
    let frequency = {};
    // Count frequency of each character in `s`
    for (let element of s) {
    frequency[element] = (frequency[element] || 0) + 1;
    }
    // Decrement frequency count for each character in `t`
    for (let element of t) {
    if (!frequency[element]) {
    return false;
    }
    frequency[element]--;
    }
    // If all values in frequency are zero, the strings are anagrams
    for (let count in frequency) {
    if (frequency[count] !== 0) {
    return false;
    }
    }
    return true;
    };