【发布时间】:2011-05-01 13:58:55
【问题描述】:
【问题讨论】:
【问题讨论】:
前段时间我在这里看到了一个类似的问题,如果有人找到链接,请编辑。 编辑:找到链接:Matrix with only 1s and 0s。解决方案是:
1. Start in the first row, most-left column
2. Go right until you hit a 0, if so, go down
3. If you hit a 1, the current row will be your new "best row"
4. Repeat from 2 until you either hit the bottom or the right border
给定一个 NxN 数组,这会在最好的情况下检查 N 个单元格,在最坏的情况下检查 N*2-1 个单元格,因此就行/列而言它是 O(N)。
【讨论】:
你的作业解决方案是:
从第一行的第一个单元格开始。如果它包含 1,则移动到同一行中的下一个单元格。如果它包含 0,则移动到下一行中的相同单元格。重复此操作,直到处理完所有行。
最后一次在行内移动的行是1个数最多的行。
【讨论】: