Leetcode 7 Reverse Integer
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
The question itself say "Environment does not allow to work with long datatype"
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;
}
}
I like it, but please write code with space around it.
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 ?
@@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
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 :)
@@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. :)
@@BogdanHladiuc got it