mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
Leetcode day 2 and 3
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
class Solution {
|
||||
public:
|
||||
int reverse(int x) {
|
||||
int rev =0;
|
||||
while(x!=0){
|
||||
int digit = x%10;
|
||||
x/=10;
|
||||
if(rev>INT_MAX/10 || rev==INT_MAX/10 && digit > 7){
|
||||
return 0;
|
||||
}
|
||||
if(rev<INT_MIN/10 || rev==INT_MIN/10 && digit < -8){
|
||||
return 0;
|
||||
}
|
||||
rev = rev*10 + digit;
|
||||
|
||||
}
|
||||
return rev;
|
||||
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
INT_MAX, INT_MIN are called integer limit macros or more generally type limit constants.(compile-time constants)
|
||||
defined in #include <climits>
|
||||
|
||||
Modern Alternative:
|
||||
|
||||
#include <limits>
|
||||
|
||||
numeric_limits<int>::max();
|
||||
numeric_limits<int>::min();
|
||||
|
||||
int maxInt = std::numeric_limits<int>::max();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user