Leetcode 1640. Check Array Formation Through Concatenation

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

// 84ms C# Solution

public class Solution {
public bool CanFormArray(int[] arr, int[][] pieces) {
int count = 0;
for (int i = 0; i < pieces.Length; ++i)
{
int tempindex = Array.IndexOf(arr, pieces[i][0]);
if (tempindex == arr.Length-1 && pieces[i].Length > 1)
return false;
for (int j = 0; j < pieces[i].Length; ++j)
{
if (Array.IndexOf(arr, pieces[i][j]) == -1)
return false;
else
{
if (arr[tempindex++] != pieces[i][j])
return false;
else
++count;
}
}
}
if (count == arr.Length)
return true;
else
return false;
}
}

Saikumar-kblf
Автор

Can someone explain line 22, why do we need it ?

mayankbhanot