## [LeetCode C++实现]36. Valid Sudoku

36. Valid Sudoku

class Solution {

public:

bool isValidSudoku(vector<vector<char>>& board) {

//row[m][n]代表第m+1行是否已使用数字n+1

//col[m][n]代表第m+1列是否已使用数字n+1

//sub_33[m][n]将格子分成了9个小的3x3,m代表第几个3x3小格子，n代表n+1是否已使用

int row[9][9] ={0},col[9][9]={0},sub_33[9][9]={0};

for(int i = 0;i < board.......

## [LeetCode C++实现]208. Implement Trie (Prefix Tree)

208. Implement Trie (Prefix Tree)

class TrieNode {

public:

// Initialize your data structure here.

bool is_word;

TrieNode *children[26];

TrieNode() {

is_word = false;

for (int i = 0; i < 26; i++)

chi......

## [LeetCode C++实现]52. N-Queens II

52. N-Queens II

52的解法相对比51更简单，无需保存具体的结果，只是统计符合条件解法的个数。代码从51的解法稍加修改：

class Solution {

public:

int totalNQueens(int n) {

vector<string> nQueens(n,string(n,'.'));

int cnt = 0;

solveNQueens(nQueens,0,n,cnt);

return cnt;

}

private:

void solveNQueens(vector<string> &nQueens, int row,......

## [LeetCode C++实现]51. N-Queens

51. N-Queens

class Solution {

public:

vector<vector<string>> solveNQueens(int n) {

vector<vector<string>> res;

vector<string> nQueens(n,string(n,'.'));

solveNQueens(res,nQueens,0,n);

return res;

}

private:

void solveNQueens(vector<vector&l......

## [LeetCode C++实现]111. Minimum Depth of Binary Tree

/**

* Definition for a binary tree node.

* struct TreeNode {

* int val;

* TreeNode *left;

* TreeNode *right;

* TreeNode() : val(0), left(nullptr), right(nullptr) {}

* TreeNode(int x) : val(x), left(nullptr), right(nullptr)......

## [LeetCode C++实现]104. Maximum Depth of Binary Tree

C语言实现:

/**

* Definition for a binary tree node.

* struct TreeNode {

* int val;

* struct TreeNode *left;

* struct TreeNode *right;

* };

*/

int maxDepth(struct TreeNode* root)

{

if(NULL == root)

{

return 0;

}

int llen = maxDepth(root->left) + 1;

int rlen = maxDepth(root->right) ......

## [LeetCode C++实现]102. Binary Tree Level Order Traversal

/**

* Definition for a binary tree node.

* struct TreeNode {

* int val;

* TreeNode *left;

* TreeNode *right;

* TreeNode() : val(0), left(nullptr), right(nullptr) {}

* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}

* TreeNo......

36 -20 = 16

16 - 10 = 6

6 - 5 = 1

1 - 1 = 0

## [LeetCode C++实现]236. Lowest Common Ancestor of a Binary Tree

236. Lowest Common Ancestor of a Binary Tree

/**

* Definition for a binary tree node.

* struct TreeNode {

* int val;

* TreeNode *left;

* TreeNode *right;

* TreeNode(int x) : val(x), left(NULL), right(NULL) {}

* };

*/

class Soluti......

## [LeetCode C++实现]235. Lowest Common Ancestor of a Binary Search Tree

235. Lowest Common Ancestor of a Binary Search Tree

/**

* Definition for a binary tree node.

* struct TreeNode {

* int val;

* TreeNode *left;

* TreeNode *right;

* TreeNode(int x) : val(x), left(NULL......