LeetCode 49. Group Anagrams

Given an array of strings, group anagrams together.
这道题思路很清晰,也比较简单
对字符串排序,以排好序的字符串为键,构建hash表,值为包含字符串的list
用python实现很容易,因为由内置函数,如果改用C语言,会增加难度

继续阅读
LeetCode 47. Permutations II

LeetCode 47. Permutations II

Given a collection of numbers that might contain duplicates, return all possible unique permutations.此问题同46题思路,条件基本一致,只是给定的数组中可能有重复值,需要去掉.
假设数组A[10],我们在遍历每个元素A[i]的时候,都检查A[i]是否在A[1:i]中出现过,如果曾经出现,则直接跳过

继续阅读

LeetCode 42. Trapping Rain Water

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for contributing this image!

继续阅读