In the Leetcode Reverse Integer problem solution in C# programming Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 – 1], then return 0.
Leetcode Reverse Integer problem solution in C# programming
public class Solution {
public int Reverse(int x) {
int iRev=0;
string strRev = x.ToString();
strRev = new string (strRev.ToCharArray().Reverse().ToArray());
if(strRev.IndexOf("-") != -1)
{
strRev=strRev.Replace("-","");
strRev="-"+strRev;
}
try
{
iRev = Int32.Parse(strRev);
}
catch
{
iRev=0;
}
return iRev;
}
}
Also read,
- Leetcode Reverse Integer problem solution in C
- Leetcode Reverse Integer problem solution in Java
- Leetcode Reverse Integer problem solution in Python
- Leetcode Reverse Integer problem solution in C++