(str1 [i] || str2 [i])是什么意思,有人可以解释吗

时间:2019-08-07 14:49:52

标签: string anagram

我试图找出两个字符串是否是字谜,而这段代码验证了它们的长度是否相等。怎么样?

1 个答案:

答案 0 :(得分:0)

str1是一个(字符)数组。 str2是一个(字符)数组。

此代码检查是否:

索引i存在于str1
-OR-
索引i存在于str2

如果您的两个数组是
['a', 'b', 'c']
['w', 'x', 'y', 'z']

它可能会首先检查索引0

i=0 // 'a' exists
i=1 // 'b' exists
i=3 // 'c' exists
i=4 // 'z' exists - first didn't match, so checks second
i=5 // doesn't exist
i=6 // doesn't exist
i=7 // doesn't...