記事のディレクトリ
トピック
1662.2つの文字列配列が等しいかどうかを確認します。2つの文字列配列word1とword2を指定します。2つの配列で表される文字列が同じ場合はtrueを返し、そうでない場合はfalseを返します。
配列で表される文字列は、配列内のすべての要素を順番に連結して形成された文字列です。
例1:
输入:word1 = ["ab", "c"], word2 = ["a", "bc"]
输出:true
解释:
word1 表示的字符串为 "ab" + "c" -> "abc"
word2 表示的字符串为 "a" + "bc" -> "abc"
两个字符串相同,返回 true
例2:
输入:word1 = ["a", "cb"], word2 = ["ab", "c"]
输出:false
例3:
输入:word1 = ["abc", "d", "defg"], word2 = ["abcddefg"]
输出:true
促す:
1 <= word1.length, word2.length <= 103
1 <= word1[i].length, word2[i].length <= 103
1 <= sum(word1[i].length), sum(word2[i].length) <= 103
word1[i] 和 word2[i] 由小写字母组成
問題解決(Java)
return s1.equals(s2);
if-elseステートメントの代わりに、ここで直接使用されます
class Solution
{
public boolean arrayStringsAreEqual(String[] word1, String[] word2)
{
String s1 = "";
String s2 = "";
for(int index = 0;index < word1.length;index++)
{
s1 += word1[index];
}
for(int index = 0;index < word2.length;index++)
{
s2 += word2[index];
}
return s1.equals(s2);
}
}