aboutsummaryrefslogtreecommitdiff
path: root/challenge-337/deadmarshal/java/Ch2.java
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-09-04 22:54:01 +0100
committerGitHub <noreply@github.com>2025-09-04 22:54:01 +0100
commit8a9e8202d5d26ab799fc34e81552f0659082fb6d (patch)
treed8e8f429e0e187ac189ebeb56d1d0e4080efec61 /challenge-337/deadmarshal/java/Ch2.java
parentfae04cafc74c8726c8e1232be059871d743884ad (diff)
parent3eecbd86cbbcdd6625e09439ddf88595aa0f6149 (diff)
downloadperlweeklychallenge-club-8a9e8202d5d26ab799fc34e81552f0659082fb6d.tar.gz
perlweeklychallenge-club-8a9e8202d5d26ab799fc34e81552f0659082fb6d.tar.bz2
perlweeklychallenge-club-8a9e8202d5d26ab799fc34e81552f0659082fb6d.zip
Merge pull request #12624 from deadmarshal/TWC337
TWC337
Diffstat (limited to 'challenge-337/deadmarshal/java/Ch2.java')
-rw-r--r--challenge-337/deadmarshal/java/Ch2.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-337/deadmarshal/java/Ch2.java b/challenge-337/deadmarshal/java/Ch2.java
new file mode 100644
index 0000000000..0d13408113
--- /dev/null
+++ b/challenge-337/deadmarshal/java/Ch2.java
@@ -0,0 +1,25 @@
+public class Ch2 {
+ public static void main(String[] args) {
+ System.out.println(odd_matrix(2, 3, new int[][]{{0, 1}, {1, 1}}));
+ System.out.println(odd_matrix(2, 2, new int[][]{{1, 1}, {0, 0}}));
+ System.out.println(odd_matrix(3, 3, new int[][]{{0, 0}, {1, 2}, {2, 1}}));
+ System.out.println(odd_matrix(1, 5, new int[][]{{0, 2}, {0, 4}}));
+ System.out.println(odd_matrix(4, 2, new int[][]{{1, 0}, {3, 1}, {2, 0}, {0, 1}}));
+ }
+
+ private static int odd_matrix(int row, int col, int[][] m) {
+ int res = 0;
+ int[][] g = new int[row][col];
+ for (int[] e : m) {
+ int r = e[0], c = e[1];
+ for (int i = 0; i < row; ++i) g[i][c]++;
+ for (int j = 0; j < col; ++j) g[r][j]++;
+ }
+ for (int[] rows : g) {
+ for (int v : rows) {
+ res += v % 2;
+ }
+ }
+ return res;
+ }
+}