File tree 5 files changed +141
-2
lines changed
solution/0400-0499/0463.Island Perimeter
5 files changed +141
-2
lines changed Original file line number Diff line number Diff line change @@ -19,18 +19,23 @@ jobs:
19
19
uses : actions/checkout@v2
20
20
21
21
- name : Compress Images
22
- uses : calibreapp/image-actions@master
22
+ id : calibre
23
+ uses : calibreapp/image-actions@main
23
24
with :
24
25
githubToken : ${{ secrets.GITHUB_TOKEN }}
25
26
compressOnly : true
26
27
27
28
- name : Commit Files
29
+ if : |
30
+ steps.calibre.outputs.markdown != ''
28
31
run : |
29
32
git config --local user.email "action@github.com"
30
33
git config --local user.name "GitHub Action"
31
- git commit -m "[Automated] Optimize images" -a
34
+ git commit -m "chore: auto compress images" -a
32
35
33
36
- name : Push Changes
37
+ if : |
38
+ steps.calibre.outputs.markdown != ''
34
39
uses : ad-m/github-push-action@master
35
40
with :
36
41
github_token : ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change @@ -136,6 +136,54 @@ function islandPerimeter(grid: number[][]): number {
136
136
};
137
137
```
138
138
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
+
139
187
### ** ...**
140
188
141
189
```
Original file line number Diff line number Diff line change @@ -123,6 +123,54 @@ function islandPerimeter(grid: number[][]): number {
123
123
};
124
124
```
125
125
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
+
126
174
### ** ...**
127
175
128
176
```
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments