P15177 [GeeksforGeeks] Unique rows in boolean matrix
普及-
题目描述

Given a binary matrix your task is to find all unique rows of the given matrix in the order of their appearance in the matrix.
Example 1:
Input:
row = 3, col = 4
M[][] = {{1 1 0 1},{1 0 0 1},{1 1 0 1}}
Output: $1 1 0 1 $1 0 0 1 $
Explanation: Above the matrix of size 3x4
looks like
1 1 0 1
1 0 0 1
1 1 0 1
The two unique rows are R_{1}: {1 1 0 1} and R_{2}: {1 0 0 1}.
As R_{1 }first appeared at row-0 and R_{2} appeared at row-1, in the resulting list, R_{1} is kept before R_{2}.
Example 2:
Input:
row = 2, col = 4
M[][] = {{0 0 0 1}, {0 0 0 1}}
Output: $0 0 0 1 $
Explanation: Above the matrix of size 2x4
looks like
0 0 0 1
0 0 0 1
Only unique row is $0 0 0 1 $
Your Task:
You only need to implement the given function uniqueRow(). The function takes three arguments the first argument is a matrix M and the next two arguments are row and col denoting the rows and columns of the matrix. The function should return the list of the unique row of the matrix. Do not read input, instead use the arguments given in the function.
Note: The driver code prints the rows "$" separated. You have to just return list of rows, you do not have to worry about printing anything.
Expected Time Complexity: O(row * col)
Expected Auxiliary Space: O(row * col)
Constraints:
1<=row,col<=40
0<=M[][]<=1

输入格式

见题面

输出格式

见题面

样例输入
row = 3, col = 4 M[][] = {{1 1 0 1},{1 0 0 1},{1 1 0 1}}
样例输出
$1 1 0 1 $1 0 0 1 $