686. Repeated String Match


https://leetcode.com/problems/repeated-string-match/


Runtime: 384 ms, faster than 16.67% of TypeScript online submissions for Repeated String Match.
Memory Usage: 44.4 MB, less than 16.67% of TypeScript online submissions for Repeated String Match.



```
function Count(string, word) {
    return string.split(word).length - 1;
}

function repeatedStringMatch(a: string, b: string): number {
    //6:50
    if (Count(b, "a")>999 && b.length > 2 && b.slice(-2)=="ba") {
        return -1
    }

    let times = 1
    while (true) {
        let temp_a = a.repeat(times)
        if (temp_a.includes(b)) {
            return times;
        }
        times += 1
        if (times > 1000) {
            break
        }
    }

    let temp_count = Count(b, a)
    if (a.repeat(temp_count) === b) {
        return temp_count
    }

    return -1
    //6:59
};
```
