We know that for Single Source Shortest Path(SSSP) problem, we can

- solve it by using BFS if no weights or equal weights or equal weights during each exploration.
- solve by using Dijkstra if the graph has positive unequal weights.

For the problem in this article, we can use modified BFS…

Less is more. One of the very simple, however, very elegant idea in CS is two pointers. We can tread two layer for loop as two pointer problem. We can think the binary search as three pointers. The in place quick sort and quick select is using the two pointers…

2035. Partition Array Into Two Arrays to Minimize Sum Difference

Got stuck for the 4th questions of the last week’s weekly LC contest (LC 262 weekly contest). When review the top submissions, I found the technologies they used are pretty similar. Then I realized this should be some “common” pattern…

The word search problem can be solved by using the backtrack. The word search II is based on word search I. For the solution of word search I, it is based on backtrack. See here for word search I.

It is based on the word search I. We can use…

It is a very classical problem which can be solved by backtracking.

`typedef pair<int, int> PII;`

const vector<PII> dirs = {{0, 1},{0, -1},{1, 0},{-1, 0}};

int seen[10][10];

class Solution {

public:

string word;

vector<vector<char>> board;

int n, m;

bool backtrack(vector<PII>& candidates, int…

This is a hard problem in leetcode which can be solved by the BFS. Usually the BFS can be used to find the shortest path problem and most case only the cost of the path should be returned. For this problem, all shortest path should be found. Based on this…

Dijkstra is an important algorithm can be used to solve the SSSP problem for graphs with positive weights. A template for can be found from here.

The above problem can be solved by using exactly the Dijkstra algorithm. The basic idea is:

- build a graph by using the weight as…

We can solve the problem by using two pointers. For each row, we use two pointers:

- left and right
- left indicate the box we shoud move
- right indicate the available location to be moved.

`vector<vector<string>> rotate(vector<vector<string>>& matrix){`

const int n = matrix.size(), m = matrix[0].size()…

标题是anpu Guan Yu Wo Ai Ni的一句最有名的歌词。全部歌词谷歌“关于我爱你 歌词” 可得。对于歌词的最初来源可以看此视频中anpu的碎碎念。个人以为这里讲的是得到和失去的关系，人生中大概率失去小概率的到，所以失去才是常态（人生），得到的便是幸运（侥幸）。一直不太完全理解这句歌词，直到有一天，想到这里，且若是能够把歌词略作改动：

我拥有的都是侥幸呀，我失去的**才**是人生。

会变的更庸俗一点，不过这刚好让我可以更加容易懂这句话的意思。

BERT是一种很fancy的基于计算机学习的一种模型，我们看看bert怎么看。以下结果来自此网站。

显然在训练bert模型的时候，bert读过了这个歌词。通过学习人类的语言，bert好似也已经明白了这个道理。参考如下：

If you are a SWE, you should be familar with Coding case styles like **Camel**. If you are a python programmer, you should use lots of **Snake** coding style to name your variables.

Here I am going to introduce the **CamelSnake** name style as shown in the following example

Suppose…