leetcode

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

1447.cpp (552B)


      1 typedef vector<string> cache_t;
      2 static inline const cache_t cache = []() -> cache_t {
      3     cache_t cache(101);
      4     for (int i = 0; i <= 100; i++)
      5         cache[i] = to_string(i);
      6     return cache;
      7 }();
      8 
      9 class Solution {
     10   public:
     11     vector<string> simplifiedFractions(int n) {
     12         vector<string> ans;
     13         for (int i = 1; i <= n - 1; i++) {
     14             for (int j = i + 1; j <= n; j++) {
     15                 if (gcd(i, j) != 1) continue;
     16                 ans.push_back(cache[i] + '/' + cache[j]);
     17             }
     18         }
     19         return ans;
     20     }
     21 };