commit 9c035c488707d7eeb0f3df4c72197a8392f1346d
parent 5a08dc932bb72bf450cf0bc6f9479cae00ad0ed1
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Thu, 18 Apr 2024 14:23:04 +0200
Daily Problem
Diffstat:
2 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/Problems/0463.cpp b/Problems/0463.cpp
@@ -0,0 +1,24 @@
+class Solution {
+ public:
+ int islandPerimeter(const vector<vector<int>> &grid) const {
+ const int n = size(grid), m = size(grid[0]);
+ static int offset[] = {-1, 0, 1, 0, -1};
+ int res = 0;
+
+ for (int i = 0; i < n; i++) {
+ for (int j = 0; j < m; j++) {
+ if (!grid[i][j]) continue;
+
+ res += 4;
+ for (int k = 0; k < 4; k++) {
+ const int x = i + offset[k];
+ const int y = j + offset[k + 1];
+ if (x < 0 || y < 0 || x >= n || y >= m) continue;
+ res -= grid[x][y] == 1;
+ }
+ }
+ }
+
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -345,6 +345,7 @@ for solving problems.
| 0459 | Easy | [Repeated Substring Pattern](Problems/0459.cpp) |
| 0460 | Hard | [LFU Cache](Problems/0460.cpp) |
| 0462 | Medium | [Minimum Moves to Equal Array Elements II](Problems/0462.cpp) |
+| 0463 | Easy | [Island Perimeter](Problems/0463.cpp) |
| 0472 | Hard | [Concatenated Words](Problems/0472.cpp) |
| 0477 | Medium | [Total Hamming Distance](Problems/0477.cpp) |
| 0485 | Easy | [Max Consecutive Ones](Problems/0485.cpp) |