Problem from leetcode Surrounded Regions

This is again a classical DFS/BFS problem. This time, we search from four edges, mark all accessible O to A, then for loop the whole matrix, mark remaining O to X and change A back to O. 565 more words

Problem from leetcode Surrounded Regions

This is again a classical DFS/BFS problem. This time, we search from four edges, mark all accessible O to A, then for loop the whole matrix, mark remaining O to X and change A back to O. 565 more words

Problem from leetcode Sum Root to Leaf Numbers

There is only one method to solve this problem: traverse the tree. For traversing one tree, we can either use BFS or DFS. 278 more words

Problem from leetcode Word Ladder II

This problem is similar to , this time we need to keep the path. Again we use BFS.

```
class Solution {
public:
vector<vector> findLadders(string beginWord, string endWord, unordered_set &wordList) {
vector<vector > result;
int length = beginWord.size();
wordList.erase(beginWord);
//this time we need to keep all intermediate words during the path
queue<vector > tool;
tool.push(vector(1, beginWord));
bool found = false;
while(!tool.empty())
{
//for expanding each level, we store the words used in this level
vector usedWords;
int size = tool.size();
while(size > 0)
{
vector tmp = tool.front(); tool.pop();
string last = tmp;
bool flag = false;
for(int index = 0; index < length && !flag; ++index)
for(char c = 'a'; c <= 'z' && !flag; ++c)
{
string t = last;
t = c;
if(t == endWord)
{
found = true;
tmp.push_back(t);
result.push_back(tmp);
flag = true;
break;
}
if(wordList.find(t) != wordList.end())
{
vector h = tmp;
h.push_back(t);
tool.push(h);
usedWords.push_back(t);
}
}
--size;
}
if(found) break;
//we delete used words only after expand all path in this level
for(int i = 0; i < usedWords.size(); ++i)
wordList.erase(usedWords[i]);
}
return result;
}
};
… 13 more words
```

Problem from leetcode Word Ladder

Just a simple glance, this problem should use BFS to find the result since need to find the shortest length. In order to avoid repeating use a word, we will delete the used word from wordList. 210 more words

BFS:

```
#include <iostream>
#include <queue>
#define MAX 100
using namespace std;
int Array = {
{0, 2, 1, 0, 0, 3},
{2, 0, 0, 0, 0, 5},
{1, 0, 0, 1, 3, 0},
{0, 0, 1, 0, 2, 0},
{0, 0, 3, 2, 0, 3},
{3, 5, 0, 0, 3, 0}
};
int V = 6;
// khai bao cac mang can thiet
int color, back;
queue<int> qlist;
void PrintPath(int u, int v, int back[])
{
if(u == v){
cout << v << " ";
}
else{
// dua vao nut cha de tim duong di ngan nhat. 207 more words
```

Looking at myself across the mirror

Raising my right hand, then I raise left hand across the mirror.

Trying to parallel my purpose, but always opposite action across the mirror. 94 more words

I’ve been recently practicing and sharpening python programming and realized python is extremely NEAT compared to other languages(C/C++, JAVA or C#). Also the running time is much faster than JAVA and C#. 621 more words