-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAamazon.java
41 lines (39 loc) · 1.31 KB
/
Aamazon.java
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
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.*;
public class Aamazon {
public static void main(String[] args) {
List<String> pixels = new ArrayList<String>();
pixels.add("011");
pixels.add("101");
pixels.add("001");
getMaximumGreyness(pixels);
}
public static int getMaximumGreyness(List<String> pixels) {
// Write your code here
// 1 0 1 0 (2+2) - (2 + 1)
// 0 1 0 1
// 1 0 1 0
// String[][] matrix = new String[pixels.size()][pixels.get(0).length()];
int oneSInFirstRow = 0 ;
int oneSInFirstCol = 0 ;
int zeroInFirstRow = 0 ;
int zeroInFirstCol = 0 ;
String current = pixels.get(0);
for(int j = 0 ; j < current.length(); j++){
if(current.charAt(j) == '1'){
oneSInFirstRow++;
}
if (current.charAt(j) == '0') {
zeroInFirstRow++;
}
}
for (int i = 0; i < pixels.size(); i++) {
if (pixels.get(i).charAt(0) == '1') {
oneSInFirstCol++;
}
if (pixels.get(i).charAt(0) == '0') {
zeroInFirstCol++;
}
}
return (oneSInFirstRow + oneSInFirstCol) - (zeroInFirstRow + zeroInFirstCol);
}
}