Anagrams Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in lower-case. 首先解释一下什么是anagrams:在不考虑顺序的情况下,包含相同字母的字符串组成anagrams 例如: 1.{"eat","ate","tea","coffee"}的anagra…
题目: Given an array of strings, group anagrams together. For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return: [ ["ate", "eat","tea"], ["nat&qu…
4Sum Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: Elements in a quadruplet (a,b,c,d) must be in non-descending o…
Permutations Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. 解法一:递归 class Solution { public: vector<vector<int> > pe…
Triangle Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [], [,4], [6,,7], [4,,8,3] ] The minimum path sum from top to bottom is …
Combinations Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example,If n = 4 and k = 2, a solution is: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] 解法一:递归 递推点:加入i后,下一个加入的元素需要遍历i+1~n 因此可以基于k做递归. base cas…
Subsets Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example,If S = [1,2,3], a solution is: [ [3], [1], [2], [1,…
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * @ClassName: MatrixReshape * @Author: xiaof * @Description: TODO 566. Reshape the Matrix * * In MATLAB, there is a very useful function called 'reshape…