Skip to content

Commit be4b1dc

Browse files
committed
feat: add solutions to lc problem: No.0463
No.0463.Island Permeter
1 parent 390990b commit be4b1dc

File tree

5 files changed

+141
-2
lines changed

5 files changed

+141
-2
lines changed

.github/workflows/compress.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,23 @@ jobs:
1919
uses: actions/checkout@v2
2020

2121
- name: Compress Images
22-
uses: calibreapp/image-actions@master
22+
id: calibre
23+
uses: calibreapp/image-actions@main
2324
with:
2425
githubToken: ${{ secrets.GITHUB_TOKEN }}
2526
compressOnly: true
2627

2728
- name: Commit Files
29+
if: |
30+
steps.calibre.outputs.markdown != ''
2831
run: |
2932
git config --local user.email "action@github.com"
3033
git config --local user.name "GitHub Action"
31-
git commit -m "[Automated] Optimize images" -a
34+
git commit -m "chore: auto compress images" -a
3235
3336
- name: Push Changes
37+
if: |
38+
steps.calibre.outputs.markdown != ''
3439
uses: ad-m/github-push-action@master
3540
with:
3641
github_token: ${{ secrets.GITHUB_TOKEN }}

solution/0400-0499/0463.Island Perimeter/README.md

+48
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,54 @@ function islandPerimeter(grid: number[][]): number {
136136
};
137137
```
138138

139+
### **C++**
140+
141+
```cpp
142+
class Solution {
143+
public:
144+
int islandPerimeter(vector<vector<int>>& grid) {
145+
int m = grid.size(), n = grid[0].size();
146+
int ans = 0;
147+
for (int i = 0; i < m; ++i)
148+
{
149+
for (int j = 0; j < n; ++j)
150+
{
151+
if (grid[i][j] == 1)
152+
{
153+
ans += 4;
154+
if (i < m - 1 && grid[i + 1][j] == 1) ans -= 2;
155+
if (j < n - 1 && grid[i][j + 1] == 1) ans -= 2;
156+
}
157+
}
158+
}
159+
return ans;
160+
}
161+
};
162+
```
163+
164+
### **Go**
165+
166+
```go
167+
func islandPerimeter(grid [][]int) int {
168+
m, n := len(grid), len(grid[0])
169+
ans := 0
170+
for i := 0; i < m; i++ {
171+
for j := 0; j < n; j++ {
172+
if grid[i][j] == 1 {
173+
ans += 4
174+
if i < m-1 && grid[i+1][j] == 1 {
175+
ans -= 2
176+
}
177+
if j < n-1 && grid[i][j+1] == 1 {
178+
ans -= 2
179+
}
180+
}
181+
}
182+
}
183+
return ans
184+
}
185+
```
186+
139187
### **...**
140188

141189
```

solution/0400-0499/0463.Island Perimeter/README_EN.md

+48
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,54 @@ function islandPerimeter(grid: number[][]): number {
123123
};
124124
```
125125

126+
### **C++**
127+
128+
```cpp
129+
class Solution {
130+
public:
131+
int islandPerimeter(vector<vector<int>>& grid) {
132+
int m = grid.size(), n = grid[0].size();
133+
int ans = 0;
134+
for (int i = 0; i < m; ++i)
135+
{
136+
for (int j = 0; j < n; ++j)
137+
{
138+
if (grid[i][j] == 1)
139+
{
140+
ans += 4;
141+
if (i < m - 1 && grid[i + 1][j] == 1) ans -= 2;
142+
if (j < n - 1 && grid[i][j + 1] == 1) ans -= 2;
143+
}
144+
}
145+
}
146+
return ans;
147+
}
148+
};
149+
```
150+
151+
### **Go**
152+
153+
```go
154+
func islandPerimeter(grid [][]int) int {
155+
m, n := len(grid), len(grid[0])
156+
ans := 0
157+
for i := 0; i < m; i++ {
158+
for j := 0; j < n; j++ {
159+
if grid[i][j] == 1 {
160+
ans += 4
161+
if i < m-1 && grid[i+1][j] == 1 {
162+
ans -= 2
163+
}
164+
if j < n-1 && grid[i][j+1] == 1 {
165+
ans -= 2
166+
}
167+
}
168+
}
169+
}
170+
return ans
171+
}
172+
```
173+
126174
### **...**
127175

128176
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
int islandPerimeter(vector<vector<int>>& grid) {
4+
int m = grid.size(), n = grid[0].size();
5+
int ans = 0;
6+
for (int i = 0; i < m; ++i)
7+
{
8+
for (int j = 0; j < n; ++j)
9+
{
10+
if (grid[i][j] == 1)
11+
{
12+
ans += 4;
13+
if (i < m - 1 && grid[i + 1][j] == 1) ans -= 2;
14+
if (j < n - 1 && grid[i][j + 1] == 1) ans -= 2;
15+
}
16+
}
17+
}
18+
return ans;
19+
}
20+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
func islandPerimeter(grid [][]int) int {
2+
m, n := len(grid), len(grid[0])
3+
ans := 0
4+
for i := 0; i < m; i++ {
5+
for j := 0; j < n; j++ {
6+
if grid[i][j] == 1 {
7+
ans += 4
8+
if i < m-1 && grid[i+1][j] == 1 {
9+
ans -= 2
10+
}
11+
if j < n-1 && grid[i][j+1] == 1 {
12+
ans -= 2
13+
}
14+
}
15+
}
16+
}
17+
return ans
18+
}

0 commit comments

Comments
 (0)