Redian新闻
>
这两道题(CareerCup 150)的答案是不是有问题啊?
avatar
这两道题(CareerCup 150)的答案是不是有问题啊?# JobHunting - 待字闺中
s*0
1
大家觉得呢?
Imagine you have a square matrix, where each cell is filled with either
black or
white. Design an algorithm to find the maximum subsquare such that all four
borders are filled with black pixels.
Assumption: Square is of size NxN.
This algorithm does the following:
1. Iterate through every (full) column from let to right.
2. At each (full) column, look at the subcolumns (from biggest to smallest).
3. At each subcolumn, see if you can form a square with the subcolumn as the
left side. If
so, update currentMaxSize and go to the next (full) column.
4. If N - col <= currentMaxSize, then break completely. We’ve found the
largest square
possible.
。。。
Time complexity: O(N^2)
不觉得可以是O(N^2). 光是step 2就要N^2了。加上step 1的循环,就是N^3了。而且
step 3要用O(1)需要pre-processing.
avatar
j*8
2
too simple, sometimes too naive.

four
smallest).
the

【在 s*********0 的大作中提到】
: 大家觉得呢?
: Imagine you have a square matrix, where each cell is filled with either
: black or
: white. Design an algorithm to find the maximum subsquare such that all four
: borders are filled with black pixels.
: Assumption: Square is of size NxN.
: This algorithm does the following:
: 1. Iterate through every (full) column from let to right.
: 2. At each (full) column, look at the subcolumns (from biggest to smallest).
: 3. At each subcolumn, see if you can form a square with the subcolumn as the

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。