摘要: 一.Pascal's TriangleGivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,... 阅读全文
posted @ 2015-11-23 20:51 zengzy 阅读(138) 评论(0) 推荐(0) 编辑
摘要: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl... 阅读全文
posted @ 2015-11-14 13:16 zengzy 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 这是使用DFS来解数组类题的典型题目,像求子集,和为sum的k个数也是一个类型 解题步骤: 1:有哪些起点,例如,数组中的每个元素都有可能作为起点,那么用个for循环就可以了。 2:是否允许重复组合 3:处理某个数,判断结果 4:dfs递归 5:还原现场 一:Permutations Given a 阅读全文
posted @ 2015-11-13 12:21 zengzy 阅读(445) 评论(0) 推荐(0) 编辑
摘要: 一:Majority ElementGiven an array of sizen, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋times.You may a... 阅读全文
posted @ 2015-11-12 23:28 zengzy 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 以下三个问题的典型的两个指针处理数组的问题,一个指针用于遍历,一个指针用于指向当前处理到位置 一:Remove Element Given an array and a value, remove all instances of that value in place and return the 阅读全文
posted @ 2015-11-12 23:15 zengzy 阅读(216) 评论(0) 推荐(0) 编辑
摘要: You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?一圈一圈的调整,关键是找到变换的各个坐... 阅读全文
posted @ 2015-11-12 21:21 zengzy 阅读(187) 评论(0) 推荐(0) 编辑
摘要: Rotate an array ofnelements to the right byksteps.For example, withn= 7 andk= 3, the array[1,2,3,4,5,6,7]is rotated to[5,6,7,1,2,3,4].Note:Try to come... 阅读全文
posted @ 2015-11-12 16:06 zengzy 阅读(183) 评论(0) 推荐(0) 编辑
摘要: Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, wh... 阅读全文
posted @ 2015-11-12 15:04 zengzy 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 一:Find Minimum in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 阅读全文
posted @ 2015-11-12 14:55 zengzy 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 一:Search in Sorted Array二分查找,可有重复元素,返回target所在的位置,只需返回其中一个位置,代码中的查找范围为[low,high),左闭右开,否则容易照成死循环。代码:class Solution {public: int search(vector& nums,... 阅读全文
posted @ 2015-11-12 12:21 zengzy 阅读(277) 评论(0) 推荐(0) 编辑
levels of contents