作者:
ZooseWu (N5)
2023-12-01 09:52:421662. Check If Two String Arrays are Equivalent
給你兩個字串陣列
回傳兩個陣列是否表示相同字串
把陣列元素按順序連接在一起之後就是他的字串
Input: word1 = ["ab", "c"], word2 = ["a", "bc"]
Output: true
word1: "ab" + "c" -> "abc"
word2: "a" + "bc" -> "abc"
Input: word1 = ["a", "cb"], word2 = ["ab", "c"]
Output: false
Input: word1 = ["abc", "d", "defg"], word2 = ["abcddefg"]
Output: true
Approach:
用join合併之後直接比較
TS Code:
function arrayStringsAreEqual (word1: string[], word2: string[]): boolean {
return word1.join('') === word2.join('')
}