- Permutations
Medium
Given a collection of distinct integers, return all possible permutations.
Example:
1 | |
这个题可以考虑循环和递归(深度优先、广度优先搜索)
一个递归的思路如下
1 | |
- Permutations II
Medium
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
Example:
1 | |
这个题在上题的基础上增加了难度
依旧考虑递归(dfs),不过考虑到不重复,首先排序,然后不搜索重复项
1 | |
- Rotate Image
Medium
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
Note:
You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
Example 1:
1 | |
这个题原地旋转,考虑一次旋转4个位置
1 | |
- Group Anagrams
Medium
Given an array of strings, group anagrams together.
Example:
1 |
|
- Group Anagrams
Medium
Given an array of strings, group anagrams together.
Example:
1 |
|
Note:
- All inputs will be in lowercase.
- The order of your output does not matter.
这是一个哈希的问题,最好的办法就是存字典了
1 | |