From 3eecbd86cbbcdd6625e09439ddf88595aa0f6149 Mon Sep 17 00:00:00 2001 From: Ali Date: Thu, 4 Sep 2025 08:40:30 +0330 Subject: TWC337 --- challenge-337/deadmarshal/java/Ch2.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 challenge-337/deadmarshal/java/Ch2.java (limited to 'challenge-337/deadmarshal/java/Ch2.java') 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; + } +} -- cgit