代码改变世界

[LeetCode]Number of Islands

2015-04-08 19:59 by 庸男勿扰, 193 阅读, 0 推荐, 收藏, 编辑
摘要:原题链接:https://leetcode.com/problems/number-of-islands/题意描述:Given a 2d grid map of'1's (land) and'0's (water), count the number of islands. An island is... 阅读全文

[LeetCode]Binary Tree Right Side View

2015-04-06 17:36 by 庸男勿扰, 182 阅读, 0 推荐, 收藏, 编辑
摘要:原题链接:https://leetcode.com/problems/binary-tree-right-side-view/题意描述:Given a binary tree, imagine yourself standing on therightside of it, return the v... 阅读全文

[LeetCode]House Robber

2015-04-06 17:31 by 庸男勿扰, 250 阅读, 0 推荐, 收藏, 编辑
摘要:原题链接:https://leetcode.com/problems/house-robber/题意描述:You are a professional robber planning to rob houses along a street. Each house has a certain amo... 阅读全文

[微软实习生2014]K-th string

2014-05-17 18:32 by 庸男勿扰, 272 阅读, 0 推荐, 收藏, 编辑
摘要:很久之前的事情了,微软2014实习生的在线测试题,记录下来以备后用。题目描述:DescriptionConsider a string set that each of them consists of {0, 1} only. All strings in the set have the sam... 阅读全文

[数字技巧]子集问题(寻找给定集合的所有子集)

2014-03-24 19:50 by 庸男勿扰, 2712 阅读, 0 推荐, 收藏, 编辑
摘要:我们定义该问题如下: 给定一个集合C,找出所有的集合C',使得C'包含于C。一、无重复元素的集合 我们首先来考虑一种简单的情形,C中的数都是各不相同的,这就意味着所产生的子集不会有重复的。 直观来说,求一个集合的子集,无非就是对每个元素进行枚举,枚举两种状态”选“还是”不选“。例如,对一个集合C,当对cur这个位置的元素进行枚举时,对剩余的元素可以递归调用这个枚举的过程,当cur为数组长度n时,代表枚举结束。 子集的解空间又叫子集树,其叶子节点所代表的状态即为所有的子集。例如,集合{1,3,5},其子集树如下所示: 如上图所示,共有8个叶子节点,代表8个子集,有了子集树,要求出 阅读全文

[LeetCode]Subsets II

2014-03-24 19:49 by 庸男勿扰, 236 阅读, 0 推荐, 收藏, 编辑
摘要:原题链接:http://oj.leetcode.com/problems/subsets-ii/题意描述:Given a collection of integers that might contain duplicates,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,IfS=[1,2,2], a solution is:[ [2]. 阅读全文

[LeetCode]Subsets

2014-03-23 23:34 by 庸男勿扰, 258 阅读, 0 推荐, 收藏, 编辑
摘要:原题链接:http://oj.leetcode.com/problems/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,IfS=[1,2,3], a solution is:[ [3], [1], [2], [1,2,3], [1,3],... 阅读全文

[LeetCode]Pascal's Triangle

2014-03-15 23:23 by 庸男勿扰, 122 阅读, 0 推荐, 收藏, 编辑
摘要:原题链接:http://oj.leetcode.com/problems/pascals-triangle/题意描述:GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]题解: 两端为1,中间为v[i][j] = v[i-1][j-1]+v[i-1][j]; 1 class Solution { 2 public: 3 vector > ... 阅读全文

[LeetCode]Reverse Integer

2014-03-14 23:53 by 庸男勿扰, 166 阅读, 0 推荐, 收藏, 编辑
摘要:原题链接:http://oj.leetcode.com/problems/reverse-integer/题意描述:Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before coding. Bonus points for you if you have already thought thro 阅读全文

[LeetCode]Linked List Cycle II

2014-03-14 17:12 by 庸男勿扰, 176 阅读, 0 推荐, 收藏, 编辑
摘要:原题链接:http://oj.leetcode.com/problems/linked-list-cycle-ii/题意描述:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?题解: 这道题的v1版本是判断一个单链表是否有环,当时我们采用的是快慢指针的方法。传送门:http://www.cnblogs.com/codershell/p/3600100.. 阅读全文