| | 1 | | // -------------------------------------------------------------------------------- |
| | 2 | | // Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv). |
| | 3 | | // All Rights Reserved. |
| | 4 | | // -------------------------------------------------------------------------------- |
| | 5 | | // This software is the confidential and proprietary information of Eugene Eremeev |
| | 6 | | // (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not |
| | 7 | | // disclose such Confidential Information and shall use it only in accordance with |
| | 8 | | // the terms of the license agreement you entered into with Eugene Eremeev (also |
| | 9 | | // known as Yevhenii Yeriemeieiv). |
| | 10 | | // -------------------------------------------------------------------------------- |
| | 11 | |
|
| | 12 | | namespace LeetCode.Algorithms.CountAndSay; |
| | 13 | |
|
| | 14 | | /// <inheritdoc /> |
| | 15 | | public class CountAndSayPrecomputed : ICountAndSay |
| | 16 | | { |
| 1 | 17 | | private static readonly string[] Precomputed = |
| 1 | 18 | | [ |
| 1 | 19 | | "1", |
| 1 | 20 | | "11", |
| 1 | 21 | | "21", |
| 1 | 22 | | "1211", |
| 1 | 23 | | "111221", |
| 1 | 24 | | "312211", |
| 1 | 25 | | "13112221", |
| 1 | 26 | | "1113213211", |
| 1 | 27 | | "31131211131221", |
| 1 | 28 | | "13211311123113112211", |
| 1 | 29 | | "11131221133112132113212221", |
| 1 | 30 | | "3113112221232112111312211312113211", |
| 1 | 31 | | "1321132132111213122112311311222113111221131221", |
| 1 | 32 | | "11131221131211131231121113112221121321132132211331222113112211", |
| 1 | 33 | | "311311222113111231131112132112311321322112111312211312111322212311322113212221", |
| 1 | 34 | | "132113213221133112132113311211131221121321131211132221123113112221131112311332111213211322211312113211", |
| 1 | 35 | | "111312211312111322212321121113122123211231131122211211131221131112311332211213211321322113311213212312311211131 |
| 1 | 36 | | "311311222113111231133211121312211231131122111213122112132113213221123113112221133112132123222112111312211312111 |
| 1 | 37 | | "132113213221133112132123123112111311222112132113212231121113112221121113122113121113222112132113213221232112111 |
| 1 | 38 | | "111312211312111322212321121113121112131112132112311321322112111312211312112213211231132132211231131122211311123 |
| 1 | 39 | | "311311222113111231133211121312211231131112311211133112111312211213211312111322211231131122211311122122111312211 |
| 1 | 40 | | "132113213221133112132123123112111311222112132113311213211231232112311311222112111312211311123113322112132113213 |
| 1 | 41 | | "111312211312111322212321121113121112131112132112311321322112111312212321121113122112131112131221121321132132211 |
| 1 | 42 | | "311311222113111231133211121312211231131112311211133112111312211213211312111322211231131122111213122112311311222 |
| 1 | 43 | | "132113213221133112132123123112111311222112132113311213211231232112311311222112111312211311123113322112132113212 |
| 1 | 44 | | "111312211312111322212321121113121112131112132112311321322112111312212321121113122112131112131221121321132132211 |
| 1 | 45 | | "311311222113111231133211121312211231131112311211133112111312211213211312111322211231131122111213122112311311222 |
| 1 | 46 | | "132113213221133112132123123112111311222112132113311213211231232112311311222112111312211311123113322112132113212 |
| 1 | 47 | | "111312211312111322212321121113121112131112132112311321322112111312212321121113122112131112131221121321132132211 |
| 1 | 48 | | "311311222113111231133211121312211231131112311211133112111312211213211312111322211231131122111213122112311311222 |
| 1 | 49 | | ]; |
| | 50 | |
|
| | 51 | | /// <summary> |
| | 52 | | /// Time complexity - O(1) |
| | 53 | | /// Space complexity - O(1) |
| | 54 | | /// </summary> |
| | 55 | | /// <param name="n"></param> |
| | 56 | | /// <returns></returns> |
| | 57 | | public string CountAndSay(int n) |
| 4 | 58 | | { |
| 4 | 59 | | return Precomputed[n - 1]; |
| 4 | 60 | | } |
| | 61 | | } |