Skip to content

Instantly share code, notes, and snippets.

@DarioAle
Created April 23, 2018 23:23
Show Gist options
  • Save DarioAle/20575c44235737782c9ce0b178674004 to your computer and use it in GitHub Desktop.
Save DarioAle/20575c44235737782c9ce0b178674004 to your computer and use it in GitHub Desktop.
bool like0hn0(std::vector<std::vector<int>> grid) {
for(int i = 0; i < grid.size(); i++)
for(int j = 0; j < grid.size(); j++)
if(grid[i][j != 0])
if(!isValid(grid, i, j)) return false;
}
bool isValid(std::vector<std::vector<int>> grid, int i, int j) {
int value = grid[i][j];
int x = i;
while(grid[x][j] != 0)
if(--x > 0)
value--;
x = i;
while(grid[x][j] != 0)
if(++x < grid.size())
value--;
x = j;
while(grid[i][x] != 0)
if(--x > 0)
value--;
x = j;
while(grid[i][x] != 0)
if(++x < grid.size())
value--;
return value == 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment