Skip to content

Instantly share code, notes, and snippets.

@totem3
Created August 15, 2020 05:06
Show Gist options
  • Save totem3/460123c290a835f55ea20c7ee0e882ab to your computer and use it in GitHub Desktop.
Save totem3/460123c290a835f55ea20c7ee0e882ab to your computer and use it in GitHub Desktop.
asanのheap buffer overflowになる
#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