Java 5ms Solution, with examination, easy to understand
Based on aaaeeeo 's solution.\nhttps://discuss.leetcode.com/topic/70887/very-clean-and-short-7ms-java-solution-based-on-70664914-s-idea\n\npublic int getMaxRepe
Based on aaaeeeo 's solution.\nhttps://discuss.leetcode.com/topic/70887/very-clean-and-short-7ms-java-solution-based-on-70664914-s-idea\n```\npublic int getMaxRepetitions(String s1, int n1, String s2, int n2) {\n        if (s1 == null || s2 == null || n1 <= 0 || n2 <= 0) {\n            return 0;\n        }\n        HashMap<Integer, Integer> posMap = new HashMap<Integer, Integer>(); // key: the rest position of s2  value:the number of s1\n        int[] repTimes = new int[102]; // repTimes[i]: nummer of used s1 is i, repetitions times is repTimes[i]\n        char[] chars1 = s1.toCharArray();\n        char[] chars2 = s2.toCharArray();\n        int len1 = s1.length();\n        int len2 = s2.length();\n        int s1Num = 1;\n        int posInS2 = 0;\n        int times = 0;\n        while (s1Num <= n1) {\n            for (int j = 0; j < len1; j++) {\n                if (chars1[j] == chars2[posInS2]) {\n                    posInS2++;\n                    if (posInS2 == len2) {\n                        times++;\n                        posInS2 = 0;\n                    }\n                }\n            }\n            repTimes[s1Num] = times;\n            if (posMap.containsKey(posInS2)) {\n                break;\n            }\n            posMap.put(posInS2, s1Num);\n            s1Num++;\n        }\n        if (s1Num >= n1) {\n            return times / n2;\n        }\n        int k = posMap.get(posInS2);\n        int s1NumInLoop = s1Num - k; // s1 num in each loop\n        int s2NumInLoop = repTimes[s1Num] - repTimes[k]; // s2 num in each loop\n        int repeatCount = (n1 - k) / s1NumInLoop;\n        int n = repeatCount * s2NumInLoop;\n        n += repTimes[k + (n1 - k) % s1NumInLoop];\n        return n / n2;\n    }\n```
[]