[ 命名建議 ] LeetCode 1640. Check Array Formation Through Concatenation #106
Answered
by
twy30
LPenny-github
asked this question in
Q&A
-
|
原 issue: LeetCode: [ 題目看嘸 ]: 再麻煩 @twy30 給予命名建議 orz 感激不盡 using System;
public class Solution
{
public static bool CanFormArray(int[] arr, int[][] pieces)
{
int[] targetArray = arr;
int[][] piecesOfPuzzles = pieces;
for (int i = 0; i < piecesOfPuzzles.Length; ++i)
{
int firstPuzzleIndex = Array.IndexOf(targetArray, piecesOfPuzzles[i][0]);
if (firstPuzzleIndex < 0)
{
return false;
}
for (int k = 1; k < piecesOfPuzzles[i].Length; ++k)
{
// targetArray = [64,4]
// piecesOfPuzzles = [[4,64]]
// firstPuzzleIndex = 1+1(k) >= 2(targetArray.Length)
if (firstPuzzleIndex + k >= targetArray.Length)
{
return false;
}
// targetArray = [64,4,32]
// piecesOfPuzzles = [[4,64],[32]]
// piecesOfPuzzles[0][1] = 64
// targetArray[ 1(firstPuzzleIndex) + 1(k) ] = 32
if (piecesOfPuzzles[i][k] != targetArray[firstPuzzleIndex + k])
{
return false;
}
}
}
return true;
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
twy30
Dec 22, 2020
Replies: 1 comment 1 reply
-
|
@ 你好 😊 一般來說,
int[][] piecesOfPuzzles = pieces;可以考慮使用 int firstPuzzleIndex = Array.IndexOf(targetArray, piecesOfPuzzles[i][0]);如果之前是用 可以參考看看 😊 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
LPenny-github
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@LPenny-github
@
你好 😊
一般來說,
可以考慮使用
puzzlePieces。如果之前是用
puzzlePieces,這裡我會改成firstPieceIndex。可以參考看看 😊