Created
April 23, 2018 23:23
-
-
Save DarioAle/20575c44235737782c9ce0b178674004 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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