rewrite leetcode maximal rectangle