My Solutions
1. Use the DP\n\n/**\n * the dp solution is employed.\n * dp[length][bit_mask]\n * where `length` is in the range [0, n], both inclusive\n *       `bit_mask` ha
**1. Use the DP**\n```\n/**\n * the dp solution is employed.\n * dp[length][bit_mask]\n * where `length` is in the range [0, n], both inclusive\n *       `bit_mask` has the length of 4\n * 1. the first bit stands for whether the character `l` exists in the string of the length `length`\n * 2. the second bit and the third bit stand for the following\n *    1) `00` stands for no characters `e` exist in the string of the length `length`\n *    2) `01` stands for just one character `e` exists in the string of the length `length`\n *    3) `10` stands for more than one characters `e` exist in the string of the length `length`\n *    4) `11` stands for invalid situations, that is, it will never happen\n * 3. the fourth bit stands for whether the character `t` exists in the string of the length `length`\n *\n * initial:\n * dp[0][0] = 1\n *\n * induction:\n * 1. if the last character is not `l`, `e`, `t`\n *    dp[length][bit_mask] = dp[length - 1][bit_mask] * 23\n * 2. if the last character is `l`\n *    dp[length][bit_mask | 0b0001] += dp[length - 1][bit_mask]\n * 3. if the last character is `e`\n *    1). if the bit_mask is 0bX00X\n *        dp[length][bit_mask | 0b0010] += dp[length - 1][bit_mask]\n *    2). if the bit_mask is 0bX01X\n *        dp[length][(bit_mask & 0b1001) | 0b0100] += dp[length - 1][bit_mask]\n *    3). if the bit_mask is 0bX10X\n *        dp[length][bit_mask] += dp[length - 1][bit_mask]\n *    4). if the bit_mask is 0bX11X,\n *        ignore it\n * 4. if the last character is `t`\n *    dp[length][bit_mask | 0b1000] += dp[length - 1][bit_mask]\n *\n * target:\n * dp[n][0b1101]\n *\n * Time Complexity: O(n)\n * Space Complexity: O(1)\n */\nclass Solution {\n public:\n  int stringCount(const int n) {\n    constexpr int mod = 1000000007;\n    constexpr int range = 2;\n    constexpr int bits = 4;\n    constexpr int bit_masks = 1 << bits;\n    constexpr int other_letters = 26 - 3;   // `3` stands for the letters `l`, `e`, and `t`\n    constexpr int target_bit_mask = 0b1101;   // `0b1101` stands for the letters "leet"\n    constexpr int bit_l = 0b0001;\n    constexpr int bit_t = 0b1000;\n    constexpr int e_bits_mask = 0b0110;\n    constexpr int invalid_e_bits = 0b11;\n    constexpr int bit_no_e = 0b00;\n    constexpr int bit_one_e = 0b01;\n    constexpr int bit_more_e = 0b10;\n    int dp[range][bit_masks]{};\n    int previous = 0;\n    int current = 1;\n    dp[previous][0] = 1;\n    for (int length = 1; length < n + 1; ++length) {\n      for (int bit_mask = 0; bit_mask < bit_masks; ++bit_mask) {\n        const int e_bits = (bit_mask & e_bits_mask) >> 1;\n        if (e_bits == invalid_e_bits) {\n          continue;\n        }\n\n        dp[current][bit_mask] = static_cast<int>((dp[current][bit_mask] + static_cast<int>(static_cast<long long>(other_letters) * dp[previous][bit_mask] % mod)) % mod);\n        dp[current][bit_mask | bit_l] = (dp[current][bit_mask | bit_l] + dp[previous][bit_mask]) % mod;\n        if (e_bits == bit_no_e) {\n          const int current_bit_mask = bit_mask | (bit_one_e << 1);\n          dp[current][current_bit_mask] = (dp[current][current_bit_mask] + dp[previous][bit_mask]) % mod;\n        } else if (e_bits == bit_one_e) {\n          const int current_bit_mask = (bit_mask & (~e_bits_mask)) | (bit_more_e << 1);\n          dp[current][current_bit_mask] = (dp[current][current_bit_mask] + dp[previous][bit_mask]) % mod;\n        } else if (e_bits == bit_more_e) {\n          dp[current][bit_mask] = (dp[current][bit_mask] + dp[previous][bit_mask]) % mod;\n        }\n        dp[current][bit_mask | bit_t] = (dp[current][bit_mask | bit_t] + dp[previous][bit_mask]) % mod;\n      }\n      \n      previous ^= 1;\n      current ^= 1;\n      memset(dp[current], 0, sizeof(dp[current]));\n    }\n    return dp[previous][target_bit_mask];\n  }\n};\n```\n**2. Use the math**\n```\n/**\n * let `T` stand for the set of all strings of length `n`\n * let `L` stand for the set of all strings of length `n`,\n *                   each of which doesn\'t contain the letter `l`\n * let `E` stand for the set of all strings of length `n`,\n *                   each of which doesn\'t contain the letter `e` or contains just one letter `e`\n * let `T` stand for the set of all strings of length `n`,\n *                   each of which doesn\'t contain the letter `t`\n * let `|S|` stand for the number of the elements of the set `S`\n * let `A AND B` stand for the set `A` AND the set `B`\n * let `A AND B AND C` stand for the set `A` AND the set `B` AND the set `C`\n *\n * |T| = 26 ^ n\n * |L| = (26 - 1) ^ n\n * |E| = (26 - 1) ^ n + n * (26 - 1) ^ (n - 1)\n * |T| = (26 - 1) ^ n\n * |L| + |E| + |T| = (3 * (26 - 1) + n) * (26 - 1) ^ (n - 1)\n * |L AND E| = (26 - 2) ^ n + n * (26 - 2) ^ (n - 1)\n * |E AND T| = (26 - 2) ^ n + n * (26 - 2) ^ (n - 1)\n * |L AND T| = (26 - 2) ^ n\n * |L AND E| + |E AND T| + |L AND T| = (3 * (26 - 2) + 2 * n) * (26 - 2) ^ (n - 1)\n * |L AND E AND T| = (26 - 3) ^ n + n * (26 - 3) ^ (n - 1) = ((26 - 3) + n) * (26 - 3) ^ (n - 1)\n *\n * the answer = |T| - (|L| + |E| + |T|) + (|L AND E| + |E AND T| + |L AND T|) - |L AND E AND T|\n *\n * Time Complexity: O(log(n))\n * Space Complexity: O(1)\n */\nclass Solution {\n private:\n  static constexpr int mod = 1000000007;\n  \n public:\n  int stringCount(const int n) {\n    constexpr int letters = 26;\n    const int t = power(letters, n);\n    const int let1 = static_cast<int>((3LL * (letters - 1) + n) * power(letters - 1, n - 1) % mod);\n    const int let2 = static_cast<int>((3LL * (letters - 2) + 2LL * n) * power(letters - 2, n - 1) % mod);\n    const int let3 = static_cast<int>(((letters - 3LL) + n) * power(letters - 3, n - 1) % mod);\n    return (mod + (((t - let1) % mod + let2) % mod - let3) % mod) % mod;\n  }\n  \n private:\n  int power(int n, const int pow) {\n    int ret = 1;\n    int factor = n;\n    for (int p = pow; p > 0; p >>= 1) {\n      if ((p & 0b1) == 0b1) {\n        ret = static_cast<int>(static_cast<long long>(ret) * factor % mod);\n      }\n      factor = static_cast<int>(static_cast<long long>(factor) * factor % mod);\n    }\n    return ret;\n  }\n};\n```
[]