摘要:
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.Input: ["tea","and","ate","eat","den"]Output:["tea","ate","eat"]["",""]-------------> 阅读全文
摘要:
You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?如下图,首先沿逆对角线翻转一次,然后按x轴中线翻转一次。 1 public void rotate(int[][] matrix) { 2 // Start typing your Java solution below 3 // DO NOT write main() function 4 ... 阅读全文
摘要:
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2]have the following unique permutations:[1,1,2],[1,2,1], and[2,1,1].解题思路:Permutations 那题输入是不包含重复元素的,故生成的排列都是不同的,II中输入元素可能相同因而可能会产生相同的排列,这里需要去重,没有找到很好的剪枝条件,这里使用HashSet来去重,当发现已经添加过该组合 阅读全文
摘要:
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].求每个位置所有可能出现的情况:固定第一个字符,然后求后面所有字符的排列。这个时候仍把后面的所有字符分成两部分:后面字符的第一个字符,以及这个字符之后的所有字符 1 public class Solution { 2 public ArrayList> per. 阅读全文