Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

My intuition is flood-fill the BFS solution, which is O(n^4); and then I figured out a DP solution which is O(n^4)..

So I googled some hints: it can be built upon another LeetCode problem: Largest Rectangle in Histogram. With proper pre-calculation, we can make a O(n^3) solution. What's more, we can start from bottom-right to upper-left, and then make sure each '1' cell is visited only once - that's O(n^2).

http://yucoding.blogspot.com/2013/01/incomplete-leetcode-question-47-maximal.html

And as always, there's such a great solution: https://leetcode.com/discuss/20240/share-my-dp-solution

posted on 2014-08-24 08:03  Tonix  阅读(139)  评论(0编辑  收藏  举报