LeetCode Longest Palindrome Solution Explained - Java

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ก.ย. 2024

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

  • @mathssr
    @mathssr ปีที่แล้ว +8

    Your solutions are great and you go through the solution very effectively. Just one suggestion, avoid saying "it's pretty easy", multiple times because it can scare beginners.

  • @outofbody4788
    @outofbody4788 2 ปีที่แล้ว +17

    how is this considered easy?

  • @giorgi23
    @giorgi23 4 ปีที่แล้ว +13

    Really tricky to think of. Thanks Nick

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

    I was trying to this problem on my own, I closely come up with a solution, but it was to verbose. This video helped me a lot

  • @rupaldesai7098
    @rupaldesai7098 5 ปีที่แล้ว +7

    One question, why a wrapper class Integer is used in second for loop instead of primitive type?

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

      my mistake i think i accidentally typed that out

    • @NickWhite
      @NickWhite  5 ปีที่แล้ว +6

      you can use primitive type as well

    • @VinayKumar-rq5kd
      @VinayKumar-rq5kd 5 ปีที่แล้ว +1

      Anything is fine there

  • @saravanansarangan7035
    @saravanansarangan7035 5 ปีที่แล้ว +2

    The best solution Nick..Awesome

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

    Thanks a lot, ez and helpful solution!

  • @damodaranm3044
    @damodaranm3044 4 ปีที่แล้ว +11

    bro your are explaining well but starters like us cant able to catch your idea . so pls write your explaination as a psedocode and then start writing the code . so that youill get a good recognition amoung people like us .

    • @Garentei
      @Garentei 4 ปีที่แล้ว +3

      You probably shouldn't be doing competitive programming if you don't know how to code.

    • @thewatcherlollol
      @thewatcherlollol 4 ปีที่แล้ว +6

      People use leetcode for internships/jobs/competitive programming. Don't try to do leetcode just for fun lol. Learn your desired language to a certain degree first. Easies aren't easy for someone with a little bit of programming experience either. You need to fully understand your programming language to solve some easy questions. Apart from fizz buzz or defanging an IP address or whatever, lots of easies are challenging.

  • @vijaypalmanit
    @vijaypalmanit 4 ปีที่แล้ว

    I didn't get idea of using last if statement, every time you are adding even numbers to result and then 1 in the result, won't that make the same sense adding them in first place, coz you you divide something by to and multiply the result by 2 it will always be even then why if statement?

    • @oscaropdyou
      @oscaropdyou 4 ปีที่แล้ว +4

      This it to add one non-matching character to be considered palindrome string. We are allowed to add only 1 character which does not have a matching. In the example output in leetcode window("dccaccd"), it was character 'a'. Once you add one such scenario, you are not allowed to add one more e.g: 'b' which was left out from output. This was achieved as result became odd once 'a' was added.

  • @VideosOfEarth
    @VideosOfEarth 4 ปีที่แล้ว

    My like for the concise code.

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

    what if we had 3 'e' and 5 'f' other than these characters ?

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

      the if condition will only work once and after that it will never be satisfied

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

      @@kamalpreetsingh4782 oh now I got it
      Thanks bro
      After one if condition, string would become odd and will remain always after that

  • @humblerawat
    @humblerawat 5 ปีที่แล้ว

    Good explanation, So you say that add all the even characters length to palindrome's length and finally take the longest odd number character length. am I right ?

    • @HK-ct1tg
      @HK-ct1tg 4 ปีที่แล้ว

      +1

    • @dileshsolanki2383
      @dileshsolanki2383 4 ปีที่แล้ว

      @@HK-ct1tg @Vineet Rawat
      We need to add all even lengths characters but for odd length, we may take any 1 character (as a center char) if you have multiple odd characters. Also keeping in mind we will be considering all the odd values too in sum but just 1 less every time.

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

    Thanks a lot

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

    2:04

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

    Cool!!!

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

    truly greedy