摘要: 题目Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.思路1. 使用数组模拟哈希表, 数组下标0-25分别代表字符'a'-'z', a[0] 代表 'a' 在单词中出现的次数2. 排序, 只有相邻的单词才有可能是相同的3. 这么慢的方法没想到 176ms 就能通过总结1. word 起初没有对 char 数组初始化, 结果 VS 成功运行, 但 Leetcode 上却是 W 阅读全文
posted @ 2014-01-10 16:19 SangS 阅读(2675) 评论(0) 推荐(0) 编辑
摘要: 题目Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should run inO(n) time and uses constant space.思路1. 排序是 nlogn, 没有其他想法了2. 参考别人思路. 将 A[i] 月 A[A[i]] 替换, 第二遍 PASS 检查 A[i] == i代码class Solution {public: int f... 阅读全文
posted @ 2014-01-10 11:10 SangS 阅读(236) 评论(0) 推荐(0) 编辑
摘要: 题目Given a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted acco 阅读全文
posted @ 2014-01-10 10:30 SangS 阅读(896) 评论(0) 推荐(0) 编辑