https://community.topcoder.com/stat?c=problem_statement&pm=2923&rd=5854
http://www.cnblogs.com/lautsie/p/3261983.html
A group of people stand before you arranged in rows and columns. Looking from above, they form an R by C rectangle of people. You will be given a String[] people containing the height of each person. Elements of people correspond to rows in the rectangle. Each element contains a space-delimited list of integers representing the heights of the people in that row. Your job is to return 2 specific heights in a int[]. The first is computed by finding the shortest person in each row, and then finding the tallest person among them (the "tallest-of-the-shortest"). The second is computed by finding the tallest person in each column, and then finding the shortest person among them (the "shortest-of-the-tallest"). |
public
int
[] getPeople(String[] people) {
int
min = Integer.MAX_VALUE;
int
max = Integer.MIN_VALUE;
int
len1 = people.length;
if
(len1 ==
0
)
return
null
;
String[] hgts = people[
0
].split(
" "
);
int
len2 = hgts.length;
if
(len2 ==
0
)
return
null
;
int
mx[][] =
new
int
[len1][len2];
for
(
int
i =
0
; i < len1; i++) {
String line = people[i];
String[] heights = line.split(
" "
);
int
_min = Integer.MAX_VALUE;
for
(
int
j =
0
; j < len2; j++) {
int
tmp = Integer.parseInt(heights[j]);
mx[i][j] = tmp;
if
(tmp < _min) _min = tmp;
}
if
(_min > max) max = _min;
}
for
(
int
j =
0
; j < len2; j++) {
int
_max = Integer.MIN_VALUE;
for
(
int
i =
0
; i < len1; i++) {
if
(mx[i][j] > _max) _max = mx[i][j];
}
if
(_max < min) min = _max;
}
return
new
int
[] {max, min};
}