Leetcode 3195. Find the Minimum Area to Cover All Ones I

  • [Leetcode 3195. Find the Minimum Area to Cover All Ones I](#Leetcode 3195. Find the Minimum Area to Cover All Ones I)
    • [1. 解题思路](#1. 解题思路)
    • [2. 代码实现](#2. 代码实现)

1. 解题思路

这一题还是挺简单的,只要找到所有1所在的元素的上下左右4个边界,作为目标矩形的四个边即可。

2. 代码实现

给出python代码实现如下:

python 复制代码
class Solution:
    def minimumArea(self, grid: List[List[int]]) -> int:
        n, m = len(grid), len(grid[0])
        lb, rb = m, -1
        ub, db = n, -1
        for i in range(n):
            for j in range(m):
                if grid[i][j] == 1:
                    lb = min(lb, j)
                    rb = max(rb, j)
                    ub = min(ub, i)
                    db = max(db, i)
        return (rb-lb+1) * (db-ub+1)

提交代码评测得到:耗时2844ms,占用内存46.2MB。

相关推荐
sheeta199813 小时前
LeetCode 每日一题笔记 日期:2026.05.28 题目:3093. 最长公共后缀查询
linux·笔记·leetcode
菜菜的顾清寒14 小时前
力扣HOT100(36)二分查找-搜索插入位置
数据结构·算法·leetcode
圣保罗的大教堂14 小时前
leetcode 1752. 检查数组是否经排序和轮转得到 简单
leetcode
x_xbx14 小时前
LeetCode:647. 回文子串
算法·leetcode·职场和发展
兰令水15 小时前
leecodecode【二分查找】【2026.5.28打卡-java版本】
java·算法·leetcode
Brilliantwxx17 小时前
【算法题】 面试级别的二叉树题目OJ复习(下)
数据结构·c++·算法·leetcode·面试·哈希算法·推荐算法
菜菜的顾清寒17 小时前
力扣100(38)堆-数组中的第K个最大元素
算法·leetcode·排序算法
圣保罗的大教堂17 小时前
leetcode 1871. 跳跃游戏 VII 中等
leetcode
Rabitebla17 小时前
C++ 继承详解(下):默认成员函数、虚继承底层与设计取舍
c语言·开发语言·数据结构·c++·算法·leetcode
圣保罗的大教堂1 天前
leetcode 2540. 最小公共值 简单
leetcode