Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is the text editor interface.
- // Anything you type or change here will be seen by the other person in real time.
- // 9x9 grid with integers (-inf to inf)
- // return if it's a valid sudoku solution
- bool checkNumbers(vector<int> &num){
- vector<bool> found(9,false);
- for(int i=0; i<num.size(); i++){
- if(num[i] < 1 || num[i] > 9)
- return false;
- found[num[i]-1] = true;
- }
- for(int i=0; i<found.size(); i++){
- if(found[i]==false)
- return false;
- }
- return true;
- }
- bool isValid(vector<vector<int> > &grid){
- if(grid.size()!=9)
- return false;
- for(int i=0; i<9; i++){
- if(grid[i].size() != 9)
- return false;
- }
- // check each row
- for(int i=0; i<grid.size(); i++){
- vector<int>tmp;
- for(int j=0; j<grid[i].size(); j++){
- tmp.push_back(grid[i][j]);
- }
- if(!checkNumbers(tmp))
- return false;
- }
- // check each column
- for(int j=0; j<grid[0].size(); j++){
- vector<int> tmp;
- for(int i=0; i<grid.size(); i++){
- tmp.push_back(grid[i][j]);
- }
- if(!checkNumbers(tmp))
- return false;
- }
- // check each 3x3 box
- for(int i=0; i<grid.size(); i+=3){
- for(int j=0; j<grid[i].size(); j+=3){
- vector<int>tmp;
- for(int m=0; m<3; m++){
- for(int n=0; n<3; n++){
- tmp.push_back(grid[i+m][j+n]);
- if(!checkNumbers(tmp))
- return false;
- }
- }
- }
- }
- return true;
- }
- ///
- ///
- |
- | |
- | |
- | |
- struct node{
- int x;
- struct node *left;
- struct node *right;
- };
- bool checkLeftRight(node *left, node *right){
- if(left == NULL && right == NULL)
- return true;
- if(left == NULL || right == NULL)
- return false;
- if(left->x != right->x)
- return false;
- return checkLeftRight(left->left, right->right) && checkLeftRight(left->right, right->left);
- }
- bool isSymetric(node *root){
- if(root == NULL)
- return true;
- return checkLeftRight(root->left, root->right);
- }
- Scala course on coursera
- reactive programming course on coursera (followup to the scala)
- scalding on github (cascading + scala)
- summingbird on github
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement