Reverse Integer | LeetCode problem 7

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

КОМЕНТАРІ • 33

  • @gautamhelange2769
    @gautamhelange2769 Рік тому +6

    Wow! You handled overflow condition greatly, Thank You!

  • @syedaraziqa2891
    @syedaraziqa2891 2 місяці тому +1

    mam please give the package name you havent displayed it correctly on screen without which integer isnt working

  • @ayomiposolaja2016
    @ayomiposolaja2016 9 місяців тому +1

    Great explanation. Thank you.

  • @oorja1983
    @oorja1983 Рік тому +3

    Amazing...keep up the good work. I like the way you break down the problem on white board but please slow it down a little bit when you code.

  • @faizuddin4032
    @faizuddin4032 5 місяців тому +2

    Great explanation, but it would be great if you use dark theme on leetcode

  • @ganeshjaggineni4097
    @ganeshjaggineni4097 6 місяців тому +1

    NICE SUPER EXCELLENT MOTIVATED

  • @mayanksinghal1400
    @mayanksinghal1400 6 місяців тому +4

    Hello.. Thankyou for this video.
    Can you explain please why can't we use overflow condition like
    if (rev*10 > Integer.MAX_VALUE || rev*10 < Integer.MIN_VALUE)

    • @prathamgupta9166
      @prathamgupta9166 4 дні тому

      so in the question it is given that it supports a signed 32-bit integer so assume your rev variable already has a value that is the maximum value for that range and then you perform rev*10 then the resulting value goes out of range and hence you cannot write rev*10 in place of MAX_VALUE/10 . I hope this helps :) ...

  • @shivamsinghdangi751
    @shivamsinghdangi751 5 місяців тому +1

    Great Explanation .

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

    Amazing explanation

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

    Great explanation thank you😄👍

  • @Ganesh-mz1cd
    @Ganesh-mz1cd 10 місяців тому +1

    great Work !

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

    Good explanation amrutha

  • @sanjaykumarpandey4325
    @sanjaykumarpandey4325 7 місяців тому +2

    Why you are dividing by 10 to check overflow condition

    • @prateekkumar299
      @prateekkumar299 7 місяців тому

      reversed * 10 > INT_MAX would mean performing the multiplication first which could already cause overflow

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

    Really helpful

  • @KRajesh-ej7dy
    @KRajesh-ej7dy Рік тому +1

    Hello mam if rev>max or min we need to get output as 0 then y it is returning garbage value .Leet code is not accepting this code...

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

      Hi .. It is giving 0 only when rev> max or min. .I have shown in the video ,when we don't consider that condition , it would give garbage value.. I think you missed the end part of video.. Please try the code from git repo.. Leetcode is accepting the code.. Thanks!

  • @mathsworldbysuraj6278
    @mathsworldbysuraj6278 4 місяці тому +1

    If number is 6804 that is containing zero and we want reverse number 4086 then what we do? according to your solution it gives 486

    • @elitegamer8008
      @elitegamer8008 4 місяці тому

      Rev = 0
      6804%10 = 4
      Rev = rev*10+4
      Rev=4
      6804/10 = 680
      680%10 = 0
      Rev = rev *10+0
      Rev = 40
      680/10 = 68
      68%10=8
      Rev = rev*10+8
      Rev = 408
      68/10=6
      6%10=6
      Rev =rev*10+6
      Rev=4086
      6/10 =0
      Loop ends

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

    very well explained ! tysm

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

    great explanation !!!

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

    Thank you Di😊

  • @niraj.suryavanshi_
    @niraj.suryavanshi_ Рік тому +1

    Great !!

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

    Amazing

  • @SeetaSahu-os7ht
    @SeetaSahu-os7ht Місяць тому

    anybody explain me why we do not use in overflow condition {reverse> (interger.max_value - digit)/10} ?

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

    thankuu...😇

  • @devendramishra5872
    @devendramishra5872 Рік тому

    ye gys kaha se aa gya ?
    didi

    • @TechnosageLearning
      @TechnosageLearning  Рік тому

      gys?? Sorry..didn't get your question..Can you be more specific?

  • @SandraSaade
    @SandraSaade 11 місяців тому

    import java.util.*;
    class Main {
    public static void main (String [] args){
    int nums=4567;
    System.out.print(reverseInt(nums)) ;
    }
    public static int reverseInt(int n) {
    int rev=0;
    while(n>0){
    int Lastdigit=n%10;
    n=n/10;
    rev=rev*10+Lastdigit;
    }
    return rev;
    }
    }

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

    class Solution {
    public static int reverse(int x) {
    int rev = 0;
    while (x != 0) {
    int lastdigit = x % 10;
    // Check for overflow and underflow
    if (rev > Integer.MAX_VALUE / 10 || (rev == Integer.MAX_VALUE / 10 && lastdigit > 7)) return 0;
    if (rev < Integer.MIN_VALUE / 10 || (rev == Integer.MIN_VALUE / 10 && lastdigit < -8)) return 0;

    rev = (rev * 10) + lastdigit;
    x = x / 10;
    }
    return rev;
    }

    public static void main(String args[]) {
    int x = 123;
    System.out.println(reverse(x)); // Output: 321
    }
    }
    This will run in runtime 1ms
    Thank me later

  • @srishtikhurana4139
    @srishtikhurana4139 3 місяці тому

    great explanation!!