leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1447.cpp (552B)
0 typedef vector<string> cache_t; 1 static inline const cache_t cache = []() -> cache_t { 2 cache_t cache(101); 3 for (int i = 0; i <= 100; i++) 4 cache[i] = to_string(i); 5 return cache; 6 }(); 7 8 class Solution { 9 public: 10 vector<string> simplifiedFractions(int n) { 11 vector<string> ans; 12 for (int i = 1; i <= n - 1; i++) { 13 for (int j = i + 1; j <= n; j++) { 14 if (gcd(i, j) != 1) continue; 15 ans.push_back(cache[i] + '/' + cache[j]); 16 } 17 } 18 return ans; 19 } 20 };