Created
August 15, 2020 05:06
-
-
Save totem3/460123c290a835f55ea20c7ee0e882ab to your computer and use it in GitHub Desktop.
asanのheap buffer overflowになる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using std::cout; | |
using std::endl; | |
class Solution { | |
public: | |
int islandPerimeter(vector<vector<int>>& grid) { | |
int ans=0; | |
for (int i=0;i<grid.size();i++) { | |
for (int j=0;j<grid[i].size();j++) { | |
for (const auto y : {-1,1}) { | |
for (const auto x : {-1, 1}) { | |
if (i+y<0||i+y>=grid.size()||j+x<0||j+y>=grid[i].size()||grid[i+y][j+x]==0) { | |
ans++; | |
} | |
} | |
} | |
} | |
} | |
return ans; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment