diff --git a/Cpp/Competitive Programming questions/LEETCODE_Reverse_Integer.cpp b/Cpp/Competitive Programming questions/LEETCODE_Reverse_Integer.cpp new file mode 100644 index 0000000..95077d9 --- /dev/null +++ b/Cpp/Competitive Programming questions/LEETCODE_Reverse_Integer.cpp @@ -0,0 +1,22 @@ +class Solution { +public: + int reverse(int x) { + int flag=0; + long int ans=0; + if(x<0){ + flag=1; + x=abs(x); + } + while(x>0){ + ans=(ans*10)+(x%10); + x/=10; + } + if(ans>INT_MAX) + return 0; + + if(flag==1){ + return ans*(-1); + } + return ans; + } +};