From 8c0b24101bfc4892f09caf52c90a38504783db0c Mon Sep 17 00:00:00 2001 From: Kaiser-Yang <624626089@qq.com> Date: Thu, 12 Sep 2024 10:53:43 +0800 Subject: [PATCH] Finish LeetCode3195.cpp --- LeetCode/LeetCode3195.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 LeetCode/LeetCode3195.cpp diff --git a/LeetCode/LeetCode3195.cpp b/LeetCode/LeetCode3195.cpp new file mode 100644 index 00000000..0e678d6e --- /dev/null +++ b/LeetCode/LeetCode3195.cpp @@ -0,0 +1,22 @@ +// problem statement: https://leetcode.cn/problems/find-the-minimum-area-to-cover-all-ones-i/ + +#include + +using namespace std; + +class Solution { +public: + int minimumArea(vector>& grid) { + int l = numeric_limits::max(), r = numeric_limits::min(), u = numeric_limits::max(), d = numeric_limits::min(); + for (int i = 0; i < grid.size(); i++) { + for (int j = 0; j < grid[i].size(); j++) { + if (grid[i][j] == 0) { continue; } + l = min(l, j); + r = max(r, j); + u = min(u, i); + d = max(d, i); + } + } + return (r - l + 1) * (d - u + 1); + } +};