Special Positions in a Binary Matrix


Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 256M

Authors:
Problem type
Allowed languages
Java 19, Java 8

題目說明

程式輸入二維陣列,所有數字都是0或1,計算該陣列有多少「寂寞的1」。

若某元素的值是1,而且該元素所屬的橫列上只有該元素是1,而且該元素所屬的直行上只有該元素是1,則該元素稱為「寂寞的1」

本題類似LeetCode 1582

輸入格式

陣列的橫列數量、陣列的直行數量、恰好可以填滿陣列的所有元素(從第一列到最後一列,每一列從第一行到最後一行)

輸入值範圍

橫列數量>=1,直行數量>=1,除此之外,所有數字都是0或1。

輸出

「寂寞的1」的數量

sample input1

3 3 0 0 1 1 0 0 0 1 0

sample output1

3

說明

以下陣列的每個1都是寂寞的1,因為所屬的橫列與直行上面都沒有其他的1
0 0 1
1 0 0
0 1 0

sample input2

3 3 0 0 1 1 0 1 0 1 0

sample output2

1

說明

以下陣列只有最後一列的1是寂寞的1,因為其他三個1都可以在所屬的列或行看到其他的1
0 0 1
1 0 1
0 1 0

Comments

There are no comments at the moment.