细语呢喃

0%

1. Stickers to Spell Word
1. Binary Number with Alternating Bits
1. Number of Distinct Islands
1. Max Area of Island

691. Stickers to Spell Word

We are given N different types of stickers. Each sticker has a lowercase English word on it.

You would like to spell out the given target string by cutting individual letters from your collection of stickers and rearranging them.

You can use each sticker more than once if you want, and you have infinite quantities of each sticker.

What is the minimum number of stickers that you need to spell out the target? If the task is impossible, return -1.

Example 1:

Input:

Output:

Explanation:

Example 2:

Input:

Output:

Explanation:

Note:

• stickers has length in the range [1, 50].
• stickers consists of lowercase English words (without apostrophes).
• target has length in the range [1, 15], and consists of lowercase English letters.
• In all test cases, all words were chosen randomly from the 1000 most common US English words, and the target was chosen as a concatenation of two random words.
• The time limit may be more challenging than usual. It is expected that a 50 sticker test case can be solved within 35ms on average.

python BFS

DFS + 记忆化搜索超时了。。

693. Binary Number with Alternating Bits

Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.

Example 1:

Example 2:

Example 3:

Example 4:

695. Max Area of Island

Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.

Find the maximum area of an island in the given 2D array. (If there is no island, the maximum area is 0.)

Example 1:

Given the above grid, return 6. Note the answer is not 11, because the island must be connected 4-directionally.

Example 2:

Given the above grid, return 0.

Note: The length of each dimension in the given grid does not exceed 50.

dfs即可

694. Number of Distinct Islands

Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.

Count the number of distinct islands. An island is considered to be the same as another if and only if one island can be translated (and not rotated or reflected) to equal the other.

Example 1:

Given the above grid map, return 1.

Example 2:

Given the above grid map, return 3.

Notice that:

and

are considered different island shapes, because we do not consider reflection / rotation.

Note: The length of each dimension in the given grid does not exceed 50.

DFS，然后hash记录小岛形状。

1. Stickers to Spell Word
1. Binary Number with Alternating Bits
1. Number of Distinct Islands
1. Max Area of Island