Use C++ template metaprogramming to prepare the solutions at compile-time.

Just for fun... actually the code would not get accepted as LeetCode puts some compile-time restrictions, e.g. "template instantiation depth exceeds maximum of 128". It should work on a local machine (with flag "-std=c++11" or above, and "-ftemplate-depth=1000" if compiled with clang).