9. Palindrome Number | Solve without String Conversion

  Рет қаралды 8,678

ThinkFWD

ThinkFWD

Күн бұрын

Hey everyone, wanted to go a little light today on a friday and show you a solution to an easy problem. This solution will focus on using MATH! Hope you enjoy it.

Пікірлер: 26
@sarasalvatierra7198
@sarasalvatierra7198 2 жыл бұрын
i’ve searched so many videos to find the explanation of the math and you are the only one whose has explained it so well.
@angeloloria6544
@angeloloria6544 2 жыл бұрын
great video, thank you for this breaking down the math for my own sake reversing a number, ex. 123: 1) use the modulo operator to divide by 10 and return the last decimal space, which will be 3 in this case (123/10 == 12.3) 2) use Math.floor, which will round down and return the nearest whole number, which will be 12 3) use the modulo operator in the same manner as step 1, which will return a 2 (12/10 == 1.2) 4) multiply the first number we extracted (3) times 10, to put it ahead of the second number we extracted (2) 5) add our multiplication result (30) to our second extracted number (2) to get 32. we've now reversed the last two digits of our original number (123) 6) use Math.floor on our last number, which gives us 1 7) use the modulo on that number again, which gives us 1 8) multiply our current reversed number (32) times 10 to put it ahead of our last extracted number (1) 9) add our multiplication result (320) to our last extracted number (1) to get 321, our reversed number
@athirahasri9703
@athirahasri9703 5 ай бұрын
I love this one. Thank you so much!
@pinkhairblackman8141
@pinkhairblackman8141 2 жыл бұрын
since the number will be a palindrome return reverse===x; will confirm if the number is the same since its a palindrome when reversed. math.floor(i/10) decrements until i>=1 is false in loop
@UlianaSarkisova
@UlianaSarkisova 11 ай бұрын
Thank you for such an easy to understand explanation!
@Valer0n07
@Valer0n07 Жыл бұрын
What if an input = 10 or 1000 or 200? This solution will not generate a correct reversed output. But technically it will return a corect answer - false. This input (1234567899) also breaks this algorithm.
@iharisyousaf
@iharisyousaf 10 ай бұрын
What do you suggest for these cases
@josey700
@josey700 Жыл бұрын
Good day! Great content though the font size is just perfect for coding not so much for presenting
@sayeesreeram
@sayeesreeram Жыл бұрын
Great Video :)
@pweezy001
@pweezy001 2 жыл бұрын
Awesome video, thanks for sharing!
@zherebetskyi4097
@zherebetskyi4097 2 жыл бұрын
Great and very helpfull video! Thank's man!
@sarasalvatierra7198
@sarasalvatierra7198 2 жыл бұрын
you are my savior
@felipegarcialopez3701
@felipegarcialopez3701 2 жыл бұрын
Great video!
@rawstrife9762
@rawstrife9762 3 жыл бұрын
GOAT!
@dshl21
@dshl21 Жыл бұрын
thankyou
@jianqiuwang8798
@jianqiuwang8798 2 жыл бұрын
why i >= 1 ? can someone explain it ?
@dannycho2287
@dannycho2287 Жыл бұрын
on line 8, we have the following: for(let i = x; i >= 1; i = Math.floor(i/10)) {...} Now, take an input of 121 as an example. The first iteration of the for loop takes us to i = 121; i is still greater than or equal to 1; i becomes Math.floor(121/10), which is 12. The second iteration of the for loop takes us to i = 12; i is still greater than or equal to 1; i becomes Math.floor(12/10), which is 1. The third iteration of the for loop takes us to i = 1; i is still greater than or equal to 1; i becomes Math.floor(1/10), which is now 0. Since i is now NOT greater than or equal to 1, we come to an end of the for loop. By this time, we already have a reverse version of the number 121.
@jianqiuwang8798
@jianqiuwang8798 Жыл бұрын
@@dannycho2287 hello Danny, thank you so much for the explanation, I really appreciate it!
@parthgoswami3221
@parthgoswami3221 Жыл бұрын
@@dannycho2287 great explanation! thank you
@rajbannasa7662
@rajbannasa7662 Жыл бұрын
thank you so much sir
@iharisyousaf
@iharisyousaf 10 ай бұрын
It fails in case of 10
@Mikeishere1234
@Mikeishere1234 2 жыл бұрын
make more of these please
@athraafaraj8387
@athraafaraj8387 2 жыл бұрын
Very help
@RichardYoung11
@RichardYoung11 4 жыл бұрын
bring back the lofi!
@ThinkFWD
@ThinkFWD 4 жыл бұрын
I just brought it back ! :), release a new vid with it. let me know if you have any question you want solved/explained
How To Solve Algorithms - Longest Common Prefix
9:31
Web Dev Simplified
Рет қаралды 30 М.
小丑在游泳池做什么#short #angel #clown
00:13
Super Beauty team
Рет қаралды 33 МЛН
Blue Food VS Red Food Emoji Mukbang
00:33
MOOMOO STUDIO [무무 스튜디오]
Рет қаралды 35 МЛН
Nastya and balloon challenge
00:23
Nastya
Рет қаралды 25 МЛН
Cursor Is Beating VS Code (...by forking it)
18:00
Theo - t3․gg
Рет қаралды 67 М.
49. Group Anagrams | Javascript
18:58
ThinkFWD
Рет қаралды 6 М.
LeetCode Solution - 394 Decode String | Google Interview
19:42
LEETCODE 88 (JAVASCRIPT) | MERGE SORTED ARRAY
9:43
Andy Gala
Рет қаралды 11 М.
Leetcode Solution - 1.0 Two Sum | Javascript
14:25
ThinkFWD
Рет қаралды 83 М.
Sum of Digits of String After Convert
8:18
Suresh Yarava
Рет қаралды 20
小丑在游泳池做什么#short #angel #clown
00:13
Super Beauty team
Рет қаралды 33 МЛН