leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2396.cpp (531B)


      1 class Solution {
      2   public:
      3     bool isStrictlyPalindromic(int n) { return false; }
      4 };
      5 
      6 class Solution {
      7   public:
      8     bool isStrictlyPalindromic(int n) {
      9         string s = "";
     10         for (int base = n - 2, crnt = n; base >= 2; base--, crnt = n) {
     11             s.clear();
     12             do {
     13                 s += '0' + crnt % base;
     14             } while ((crnt /= base) > 0);
     15             int i = 0, j = s.size() - 1;
     16             while (i < j)
     17                 if (s[i++] != s[j--]) return false;
     18         }
     19 
     20         return true;
     21     }
     22 };