Leetcode 7 Reverse Integer

Sdílet
Vložit
  • čas přidán 2. 06. 2022
  • Leetcode 7, Reverse Integer, Leetcode Solutions, FAANG Interview questions, Leetcode Java Solutions, Leetcode Java Solution, Leetcode Solution, #Leetcode , #LeetcodeSolution #Leetcodesolutions #faang #interviewPreparation
    Connect with me on Facebook : / pratikshabakrola
    Subscribe to my channel: / @pratikshabakrola

Komentáře • 9

  • @devxbasit
    @devxbasit Před rokem

    The question itself say "Environment does not allow to work with long datatype"

  • @pratikshabakrola
    @pratikshabakrola  Před 2 lety

    class Solution {
    public int reverse(int x) {
    String str= String.valueOf(x);
    boolean negetive=false;
    StringBuilder reversedStr=new StringBuilder();
    long reverse=0;
    if(x=0;i--)
    reversedStr.append(str.charAt(i));
    reversedStr= negetive?reversedStr.insert(0,'-'): reversedStr;
    reverse= Long.parseLong(reversedStr.toString(),10) ;
    if(reverse=Integer.MIN_VALUE)
    return Integer.valueOf(reversedStr.toString());
    else
    return 0;
    }
    }

  • @vanvothe4817
    @vanvothe4817 Před 2 lety +1

    I like it, but please write code with space around it.

    • @pratikshabakrola
      @pratikshabakrola  Před 2 lety

      Hello Van,
      Thank you for your suggestion. Could you please clarify it further?
      Will it be helpful if I use the entire window for coding ?

    • @vanvothe4817
      @vanvothe4817 Před 2 lety +1

      @@pratikshabakrola I mean write code with spaces around words. Regarding the style code.
      Example:
      ```
      if(x < 0)
      {
      negative = true;
      str = str.substring(1);
      }
      ```
      Instead
      ```
      if(x

    • @pratikshabakrola
      @pratikshabakrola  Před 2 lety

      Thank you for clarifying that! I will do that for the next video I film. I have already filmed the one coming out next week so .. will incorporate it in the videos after that :)

    • @BogdanHladiuc
      @BogdanHladiuc Před 2 lety +1

      @@vanvothe4817 I would add also if (x < 0). I mean space after if. But it's just me and how I got used to it many many years ago. :)

    • @vanvothe4817
      @vanvothe4817 Před 2 lety +1

      @@BogdanHladiuc got it