Created
January 2, 2021 13:53
-
-
Save Desolve/d7ca363defdd266301bc5f37e956e7d4 to your computer and use it in GitHub Desktop.
1640 Check Array Formation Through Concatenation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: | |
idx = {} | |
for i in range(len(pieces)): | |
idx[pieces[i][0]] = i | |
cnt = 0 | |
while cnt < len(arr): | |
if arr[cnt] not in idx: | |
return False | |
p = idx[arr[cnt]] | |
for n in pieces[p]: | |
if n != arr[cnt]: | |
return False | |
cnt += 1 | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment