## 为什么要增加畅言评论

之前一直在用多说评论，但是多说就要关闭了，就是在2017年6月1日。所以必须在这之前改用新的评论系统，不然的话博客就要不能评论了（然而并没有什么人给我评论）。然后就是选择用什么评论系统了，也没有什么可参考，随便选了一个。

至于为什么要自己添加，因为我的Next版本很旧了，但是自己做过很多改动不想更新到最新版本。

戒急用忍

之前一直在用多说评论，但是多说就要关闭了，就是在2017年6月1日。所以必须在这之前改用新的评论系统，不然的话博客就要不能评论了（然而并没有什么人给我评论）。然后就是选择用什么评论系统了，也没有什么可参考，随便选了一个。

至于为什么要自己添加，因为我的Next版本很旧了，但是自己做过很多改动不想更新到最新版本。

In the video game Fallout 4, the quest “Road to Freedom” requires players to reach a metal dial called the “Freedom Trail Ring”, and use the dial to spell a specific keyword in order to open the door.

Given a string **ring**, which represents the code engraved on the outer ring and another string **key**, which represents the keyword needs to be spelled. You need to find the **minimum** number of steps in order to spell all the characters in the keyword.

Initially, the first character of the **ring** is aligned at 12:00 direction. You need to spell all the characters in the string **key** one by one by rotating the ring clockwise or anticlockwise to make each character of the string **key** aligned at 12:00 direction and then by pressing the center button.

At the stage of rotating the ring to spell the key character **key[i]**:

You can rotate the ring clockwise or anticlockwise **one place**, which counts as 1 step. The final purpose of the rotation is to align one of the string **ring’s** characters at the 12:00 direction, where this character must equal to the character **key[i]**.

If the character **key[i]** has been aligned at the 12:00 direction, you need to press the center button to spell, which also counts as 1 step. After the pressing, you could begin to spell the next character in the key (next stage), otherwise, you’ve finished all the spelling.

**Example:**

Input: ring = “godding”, key = “gd”

Output: 4

Explanation:

For the first key character ‘g’, since it is already in place, we just need 1 step to spell this character.

For the second key character ‘d’, we need to rotate the ring “godding” anticlockwise by two steps to make it become >”ddinggo”.

Also, we need 1 more step for spelling.

So the final output is 4.

**Note:**

- Length of both ring and key will be in range 1 to 100.
- There are only lowercase letters in both strings and might be some duplcate characters in both strings.
- It’s guaranteed that string key could always be spelled by rotating the string ring.

题目来自于辐射4这个游戏。有一个圆盘，圆盘上有几个英文字母，圆盘12点方向代表当前选中的字母，通过这个圆盘拼出一个和题目一样的字符串，求出最小的步数。

圆盘可以顺时针或者逆时针旋转，每旋转一个字母代表1步，当12点方向是需要的英文字母时，按确定按钮，这个按也算一步。

Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than one possible results, return the longest word with the smallest lexicographical order. If there is no possible result, return the empty string.

**Example 1:**

Input:

s = “abpcplea”, d = [“ale”,”apple”,”monkey”,”plea”]Output:

“apple”

**Example 2:**

Input:

s = “abpcplea”, d = [“a”,”b”,”c”]Output:

“a”

**Note:**

- All the strings in the input will only contain lower-case letters.
- The size of the dictionary won’t exceed 1,000.
- The length of all the strings in the input won’t exceed 1,000.

给出一个`String A`

和一个`String`

数组，在`String`

数组中找到最长的`String B`

，这个String可以满足从A中删除一些字母得到。如果满足的字符串有多个，则选择字母序最小的字符串。

Given a list of 24-hour clock time points in “Hour:Minutes” format, find the minimum **minutes** difference between any two time points in the list.

**Example 1:**

Input: [“23:59”,”00:00”]

Output: 1Note:

- The number of time points in the given list is at least 2 and won’t exceed 20000.
- The input time is legal and ranges from 00:00 to 23:59.

计算最短的时间间隔，注意24小时制值得变化。

Note: This is a companion problem to the System Design problem: Design TinyURL.

TinyURL is a URL shortening service where you enter a URL such as `https://leetcode.com/problems/design-tinyurl`

and it returns a short URL such as `http://tinyurl.com/4e9iAk`

.

Design the `encode`

and `decode`

methods for the TinyURL service. There is no restriction on how your encode/decode algorithm should work. You just need to ensure that a URL can be encoded to a tiny URL and the tiny URL can be decoded to the original URL.

完成短链接的编解码。

Let’s play the minesweeper game (Wikipedia), online game)!

You are given a 2D char matrix representing the game board. **‘M’** represents an **unrevealed** mine, **‘E’** represents an **unrevealed** empty square, **‘B’** represents a **revealed** blank square that has no adjacent (above, below, left, right, and all 4 diagonals) mines, **digit** (‘1’ to ‘8’) represents how many mines are adjacent to this **revealed** square, and finally **‘X’** represents a **revealed** mine.

Now given the next click position (row and column indices) among all the **unrevealed** squares (‘M’ or ‘E’), return the board after revealing this position according to the following rules:

If a mine (‘M’) is revealed, then the game is over - change it to **‘X’**.

If an empty square (‘E’) with **no adjacent mines** is revealed, then change it to revealed blank (‘B’) and all of its adjacent **unrevealed** squares should be revealed recursively.

If an empty square (‘E’) with **at least one adjacent mine** is revealed, then change it to a digit (‘1’ to ‘8’) representing the number of adjacent mines.

Return the board when no more squares will be revealed.

**Example 1:**

Input:

[[‘E’, ‘E’, ‘E’, ‘E’, ‘E’],

[‘E’, ‘E’, ‘M’, ‘E’, ‘E’],

[‘E’, ‘E’, ‘E’, ‘E’, ‘E’],

[‘E’, ‘E’, ‘E’, ‘E’, ‘E’]]Click : [3,0]

Output:

[[‘B’, ‘1’, ‘E’, ‘1’, ‘B’],

[‘B’, ‘1’, ‘M’, ‘1’, ‘B’],

[‘B’, ‘1’, ‘1’, ‘1’, ‘B’],

[‘B’, ‘B’, ‘B’, ‘B’, ‘B’]]Explanation:

**Example 2:**

Input:

[[‘B’, ‘1’, ‘E’, ‘1’, ‘B’],

[‘B’, ‘1’, ‘M’, ‘1’, ‘B’],

[‘B’, ‘1’, ‘1’, ‘1’, ‘B’],

[‘B’, ‘B’, ‘B’, ‘B’, ‘B’]]Click : [1,2]

Output:

[[‘B’, ‘1’, ‘E’, ‘1’, ‘B’],

[‘B’, ‘1’, ‘X’, ‘1’, ‘B’],

[‘B’, ‘1’, ‘1’, ‘1’, ‘B’],

[‘B’, ‘B’, ‘B’, ‘B’, ‘B’]]Explanation:

**Note:**

- The range of the input matrix’s height and width is [1,50].
- The click position will only be an unrevealed square (‘M’ or ‘E’), which also means the input board contains at least one clickable square.
- The input board won’t be a stage when game is over (some mines have been revealed).
- For simplicity, not mentioned rules should be ignored in this problem. For example, you don’t need to reveal all the unrevealed mines when the game is over, consider any cases that you will win the game or flag any squares.

这个题指的是扫雷游戏。在扫雷游戏中，用二维矩阵标识当前的扫雷状态。没有被发掘的空块标记为`'E'`

，没有被发掘的雷为`'M'`

，发掘之后的空块标记为`'N'`

，发掘之后的块标记为`'X'`

，另外数字`1-8`

表示该块周围有几个雷。

给出一个二维矩阵标识当天扫雷游戏的状态，然后给出下一步，求出走完下一步之后的游戏状态。

Suppose you have **N** integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these **N** numbers successfully if one of the following is true for the ith position (1 ≤ i ≤ N) in this array:

- The number at the ith position is divisible by
**i**. **i**is divisible by the number at the ith position.

Now given**N**, how many beautiful arrangements can you construct?

**Example 1:**

Input: 2

Output: 2

Explanation:The first beautiful arrangement is [1, 2]:

Number at the 1st position (i=1) is 1, and 1 is divisible by i (i=1).

Number at the 2nd position (i=2) is 2, and 2 is divisible by i (i=2).

The second beautiful arrangement is [2, 1]:

Number at the 1st position (i=1) is 2, and 2 is divisible by i (i=1).

Number at the 2nd position (i=2) is 1, and i (i=2) is divisible by 1.

**Note:**

**N**is a positive integer and will not exceed 15.

所谓`美丽的排布`

是指，在`i`

位置上的数字能够整除`i`

或者被`i`

整除，`i`

从1开始。给定一个数字`N`

，计算有多少个这样的排布。

Given a string s, find the longest palindromic subsequence’s length in s. You may assume that the maximum length of s is 1000.

**Example 1:**

Input:

“bbbab”

Output:

4

One possible longest palindromic subsequence is “bbbb”.

**Example 2:**

Input:

“cbbd”

Output:

2

One possible longest palindromic subsequence is “bb”.

查找一个字符串中包含的最长回文长度。

Think about Zuma Game. You have a row of balls on the table, colored red(R), yellow(Y), blue(B), green(G), and white(W). You also have several balls in your hand.

Each time, you may choose a ball in your hand, and insert it into the row (including the leftmost place and rightmost place). Then, if there is a group of 3 or more balls in the same color touching, remove these balls. Keep doing this until no more balls can be removed.

Find the minimal balls you have to insert to remove all the balls on the table. If you cannot remove all the balls, output -1.

**Examples:**

Input: “WRRBBW”, “RB”

Output: -1

Explanation: WRRBBW -> WRR[R]BBW -> WBBW -> WBB[B]W -> WWInput: “WWRRBBWW”, “WRBRW”

Output: 2

Explanation: WWRRBBWW -> WWRR[R]BBWW -> WWBBWW -> WWBB[B]WW -> WWWW -> emptyInput:”G”, “GGGGG”

Output: 2

Explanation: G -> G[G] -> GG[G] -> emptyInput: “RBYYBBRRB”, “YRBGB”

Output: 3

Explanation: RBYYBBRRB -> RBYY[Y]BBRRB -> RBBBRRB -> RRRB -> B -> B[B] -> BB[B] -> empty

**Note:**

- You may assume that the initial row of balls on the table won’t have any 3 or more consecutive balls with the same color.
- The number of balls on the table won’t exceed 20, and the string represents these balls is called “board” in the input.
- The number of balls in your hand won’t exceed 5, and the string represents these balls is called “hand” in the input.
- Both input strings will be non-empty and only contain characters ‘R’,’Y’,’B’,’G’,’W’.

祖玛游戏，不知道你们有没有玩儿过，我也是很久很久之前玩儿了，久到实在想不出来是什么时候的事情了。在桌上有一行球，球有5种颜色，红、黄、蓝、绿、白。你的手里也有一些这些颜色的球，每次可以选择一个球插入到桌上一行球中的任意位置，如果有3个或者3个以上相同颜色的球出现则将它们消除。然后再持续把手里的球插入到桌面一行球中，直到桌面上的这行秀全部消除。

求出能把桌面上的球全部消除的最小步数。

Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of all the node values formed by the subtree rooted at that node (including the node itself). So what is the most frequent subtree sum value? If there is a tie, return all the values with the highest frequency in any order.

**Examples 1**

Input:

5

/ \

2 -3

return [2, -3, 4], since all the values happen only once, return all of them in any order.

**Examples 2**

Input:

5

/ \

2 -5

return [2], since 2 happens twice, however -5 only occur once.

子树和的含义是指树中的一个节点所有子节点值得和（包含该节点）。一棵树每个节点都有子树和，找到存在数目最多的子树和。