9. Palindrome Number | Solve without String Conversion

  Рет қаралды 9,017

ThinkFWD

ThinkFWD

Күн бұрын

Пікірлер: 25
@sarasalvatierra7198
@sarasalvatierra7198 3 жыл бұрын
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 3 жыл бұрын
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 9 ай бұрын
I love this one. Thank you so much!
@UlianaSarkisova
@UlianaSarkisova Жыл бұрын
Thank you for such an easy to understand explanation!
@pweezy001
@pweezy001 2 жыл бұрын
Awesome video, thanks for sharing!
@pinkhairblackman8141
@pinkhairblackman8141 3 жыл бұрын
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
@StockWithSayee
@StockWithSayee Жыл бұрын
Great Video :)
@felipegarcialopez3701
@felipegarcialopez3701 3 жыл бұрын
Great video!
@jianqiuwang8798
@jianqiuwang8798 2 жыл бұрын
why i >= 1 ? can someone explain it ?
@dannycho2287
@dannycho2287 2 жыл бұрын
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 2 жыл бұрын
@@dannycho2287 hello Danny, thank you so much for the explanation, I really appreciate it!
@parthgoswami3221
@parthgoswami3221 Жыл бұрын
@@dannycho2287 great explanation! thank you
@rajbannasa7662
@rajbannasa7662 2 жыл бұрын
thank you so much sir
@josey700
@josey700 2 жыл бұрын
Good day! Great content though the font size is just perfect for coding not so much for presenting
@sarasalvatierra7198
@sarasalvatierra7198 3 жыл бұрын
you are my savior
@dshl21
@dshl21 Жыл бұрын
thankyou
@Valer0n07
@Valer0n07 2 жыл бұрын
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 Жыл бұрын
What do you suggest for these cases
@rawstrife9762
@rawstrife9762 3 жыл бұрын
GOAT!
@Mikeishere1234
@Mikeishere1234 2 жыл бұрын
make more of these please
@athraafaraj8387
@athraafaraj8387 3 жыл бұрын
Very help
@iharisyousaf
@iharisyousaf Жыл бұрын
It fails in case of 10
@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
49. Group Anagrams | Javascript
18:58
ThinkFWD
Рет қаралды 6 М.
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
Cat mode and a glass of water #family #humor #fun
00:22
Kotiki_Z
Рет қаралды 42 МЛН
How To Solve Algorithms - Longest Common Prefix
9:31
Web Dev Simplified
Рет қаралды 30 М.
LeetCode Solution - 394 Decode String | Google Interview
19:42
LeetCode Solution - 2.0 Add Two Numbers | Google Interview
14:27
LEETCODE 206 (JAVASCRIPT) | REVERSE LINKED LIST
9:19
Andy Gala
Рет қаралды 7 М.
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН