我正在为Java中的Algorithms类的项目工作,并且我无法解决这个问题。同时比较二维数组的层
我有一个尺寸为[m] [n]的二维数组,其中m和n可以根据输入而波动。我想将这些值压缩到一个单维数组中,该数组的值是二维数组中任何垂直列的最低值。这里是数组的两个样本。
样品1个输入:
3.0, 4.0, 2.0, 3.0, 4.0, 2.0, 1.0, 2.0, 0.0, 3.0, 3.0
0.0, 1.0, 1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 3.0, 2.0, 2.0
样品1个输出:
0.0, 1.0, 1.0, 2.0, 3.0, 1.0, 1.0, 2.0, 0.0, 2.0, 2.0
样品2输入:
0.0, 1.0, 1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 3.0, 2.0, 2.0
2.0, 3.0, 1.0, 0.0, 1.0, 3.0, 2.0, 3.0, 3.0, 4.0, 2.0
1.0, 2.0, 2.0, 3.0, 4.0, 0.0, 1.0, 2.0, 2.0, 1.0, 3.0
1.0, 2.0, 0.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0, 3.0, 1.0
2.0, 3.0, 1.0, 2.0, 3.0, 1.0, 0.0, 1.0, 1.0, 2.0, 2.0
样品2输出:
0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0
这是我要排序的逻辑是这样的:
loop through the 2-d array
at every vertical index, compare all values within the vertical index,
output lowest value to single dimensional array
我相信这是一个有些简单的问题,但我不能换我围绕如何做到这一点正确的头。感谢您提供任何建议!
[一(http://meta.programmers.stackexchange.com/questions/6166/open-letter-to-students-with-homework-problems) –