2013年10月11日

Combination Sum

摘要: Given a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thesamerepeated num... 阅读全文

posted @ 2013-10-11 13:12 Step-BY-Step 阅读(187) 评论(0) 推荐(0) 编辑

First Missing Positive

摘要: 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 ru... 阅读全文

posted @ 2013-10-11 13:10 Step-BY-Step 阅读(124) 评论(0) 推荐(0) 编辑

Trapping Rain Water

摘要: Givennnon-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.For example,Given[0,1,0,2,1,0,1,3,2,1,2,1], return6.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 阅读全文

posted @ 2013-10-11 11:58 Step-BY-Step 阅读(151) 评论(0) 推荐(0) 编辑

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,... 阅读全文

posted @ 2013-10-11 11:56 Step-BY-Step 阅读(179) 评论(0) 推荐(0) 编辑

Single Number II

摘要: Given an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?创建一个长度为32的数组a,a[i]表示所有数字在i位出现的次数。假如a[i]是3的整数倍,则忽略;否则就把该位取出来组成答案。空间复杂度O(1).int sol1(int A[], 阅读全文

posted @ 2013-10-11 11:17 Step-BY-Step 阅读(278) 评论(0) 推荐(0) 编辑

Single Number

摘要: Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?这题是Amazon的经典面试题。 最简单的解法是用hashmap,O(n)即可。但是要用额外的存储空间。或者是维持一个数组,用于存放没有被配对的数。用二分来更新这个数组,如果数组中没有当前数就加入 阅读全文

posted @ 2013-10-11 11:06 Step-BY-Step 阅读(212) 评论(0) 推荐(0) 编辑

Copy List with Random Pointer

摘要: Question: There is a doubly linked list with next pointer and random pointer (points to an arbitrary node in list). You have to make a copy of the linked list and return. In the end original list shouldn't be modified. Time complexity should be O(n).这个是微软经典list题目之一: 铁索连舟. 本来是想自己写一篇总结的, 但是网上那篇英文的 阅读全文

posted @ 2013-10-11 08:25 Step-BY-Step 阅读(936) 评论(0) 推荐(1) 编辑

导航