Last active
September 12, 2015 17:39
-
-
Save balamark/1b984bb3c5acb05c76ff to your computer and use it in GitHub Desktop.
editorial version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PalindromicNumbers { | |
public: | |
int countPalNums(int lower, int upper) { | |
string s,t; | |
int cnt=0; | |
for(int even=1;even<10000;even++){ | |
t = s = to_string(even); | |
reverse(s.begin(), s.end()); | |
if(lower<=stoi(t+s) && stoi(t+s)<=upper) cnt++; | |
} | |
for(int odd=1;odd<100000;odd++){ | |
t = s = to_string(odd); | |
reverse(s.begin(), s.end()); | |
t.resize(t.size()-1); | |
if(lower<=stoi(t+s) && stoi(t+s)<=upper) cnt++; | |
} | |
return cnt; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment