leetcode

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

1006.cpp (443B)


      1 class Solution {
      2     static int other(int n) {
      3         if (n <= 0) return 0;
      4         int res = n;
      5         if (n > 1) res *= n - 1;
      6         if (n > 2) res /= n - 2;
      7         if (n > 3) res -= n - 3;
      8         return res + other(n - 4);
      9     }
     10 
     11   public:
     12     int clumsy(int n) const {
     13         int res = n;
     14         if (n > 1) res *= n - 1;
     15         if (n > 2) res /= n - 2;
     16         if (n > 3) res += n - 3;
     17         return res - other(n - 4);
     18     }
     19 };