1252. Cells with Odd Values in a Matrix ¶
Approach 1: Traverse all cells¶
- Time: $O(mn + |\texttt{indices}|)$
- Space: $O(m + n)$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Approach 2: Math¶
- Time: $O(m + n + |\texttt{indices}|)$
- Space: $O(m + n)$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Approach 3: Math (Set)¶
- Time: $O(|\texttt{indices}|)$
- Space: $O(|\texttt{indices}|)$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|