11 2015 档案

摘要:Given an array ofnpositive integers and a positive integers, find the minimal length of a subarray of which the sum ≥s. If there isn't one, return 0 i... 阅读全文
posted @ 2015-11-30 10:47 zengzy 阅读(209) 评论(0) 推荐(0)
摘要:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpo 阅读全文
posted @ 2015-11-30 00:34 zengzy 阅读(153) 评论(0) 推荐(0)
摘要:Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially... 阅读全文
posted @ 2015-11-30 00:01 zengzy 阅读(178) 评论(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].主要是考虑几种情况:1.起点... 阅读全文
posted @ 2015-11-29 22:45 zengzy 阅读(185) 评论(0) 推荐(0)
摘要:Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from l... 阅读全文
posted @ 2015-11-29 21:55 zengzy 阅读(159) 评论(0) 推荐(0)
摘要: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.Fo... 阅读全文
posted @ 2015-11-29 20:02 zengzy 阅读(144) 评论(0) 推荐(0)
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文
posted @ 2015-11-29 15:01 zengzy 阅读(189) 评论(0) 推荐(0)
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文
posted @ 2015-11-29 12:17 zengzy 阅读(140) 评论(0) 推荐(0)
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie... 阅读全文
posted @ 2015-11-29 11:18 zengzy 阅读(170) 评论(0) 推荐(0)
摘要:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest ... 阅读全文
posted @ 2015-11-29 11:03 zengzy 阅读(139) 评论(0) 推荐(0)
摘要:A peak element is an element that is greater than its neighbors.Given an input array wherenum[i] ≠ num[i+1], find a peak element and return its index.... 阅读全文
posted @ 2015-11-29 02:00 zengzy 阅读(133) 评论(0) 推荐(0)
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Pana... 阅读全文
posted @ 2015-11-29 00:11 zengzy 阅读(165) 评论(0) 推荐(0)
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3,4,−1,2,1,... 阅读全文
posted @ 2015-11-28 23:54 zengzy 阅读(154) 评论(0) 推荐(0)
摘要:Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:Yo... 阅读全文
posted @ 2015-11-28 23:43 zengzy 阅读(166) 评论(0) 推荐(0)
摘要:Given an arraynumscontainingn+ 1 integers where each integer is between 1 andn(inclusive), prove that at least one duplicate number must exist. Assume... 阅读全文
posted @ 2015-11-28 23:18 zengzy 阅读(159) 评论(0) 推荐(0)
摘要:268. Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example, 阅读全文
posted @ 2015-11-28 18:32 zengzy 阅读(195) 评论(0) 推荐(0)
摘要:Given an array ofnintegers wheren> 1,nums, return an arrayoutputsuch thatoutput[i]is equal to the product of all the elements ofnumsexceptnums[i].Solv... 阅读全文
posted @ 2015-11-28 17:37 zengzy 阅读(166) 评论(0) 推荐(0)
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array[2,3,-2,4],the... 阅读全文
posted @ 2015-11-28 12:22 zengzy 阅读(167) 评论(0) 推荐(0)
摘要:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the ord... 阅读全文
posted @ 2015-11-28 11:33 zengzy 阅读(186) 评论(0) 推荐(0)
摘要:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality c... 阅读全文
posted @ 2015-11-28 11:21 zengzy 阅读(141) 评论(0) 推荐(0)
摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or... 阅读全文
posted @ 2015-11-28 11:11 zengzy 阅读(133) 评论(0) 推荐(0)
摘要:Given a non-negative integernum, repeatedly add all its digits until the result has only one digit.For example:Givennum = 38, the process is like:3 + ... 阅读全文
posted @ 2015-11-28 10:53 zengzy 阅读(143) 评论(0) 推荐(0)
摘要:Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer... 阅读全文
posted @ 2015-11-28 10:37 zengzy 阅读(180) 评论(0) 推荐(0)
摘要:一.Ugly NumberWrite a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include2, 3,... 阅读全文
posted @ 2015-11-28 10:13 zengzy 阅读(196) 评论(0) 推荐(0)
摘要:Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.如果直接遍历链表数组,时间复杂度为T(n)=T(n-1)+o(lenn);即合并前n-1个链表的时间+与第n... 阅读全文
posted @ 2015-11-28 09:36 zengzy 阅读(131) 评论(0) 推荐(0)
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Def... 阅读全文
posted @ 2015-11-28 01:56 zengzy 阅读(124) 评论(0) 推荐(0)
摘要:Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that is great... 阅读全文
posted @ 2015-11-28 01:50 zengzy 阅读(148) 评论(0) 推荐(0)
摘要:Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".class Solution {public: string addBinary(str... 阅读全文
posted @ 2015-11-28 01:37 zengzy 阅读(193) 评论(0) 推荐(0)
摘要:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single ... 阅读全文
posted @ 2015-11-28 01:15 zengzy 阅读(154) 评论(0) 推荐(0)
摘要:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-nega... 阅读全文
posted @ 2015-11-28 00:15 zengzy 阅读(204) 评论(0) 推荐(0)
摘要:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at... 阅读全文
posted @ 2015-11-27 22:22 zengzy 阅读(178) 评论(0) 推荐(0)
摘要:Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.要求空间复杂度为o(1)思路:把数组划分为两部分,第一部分是第一行和第一列;第二部分是除去第一行第一列的矩阵部分。1.先记... 阅读全文
posted @ 2015-11-27 21:50 zengzy 阅读(183) 评论(0) 推荐(0)
摘要:Given a sorted integer array without duplicates, return the summary of its ranges.For example, given[0,1,2,4,5,7], return["0->2","4->5","7"].class Sol... 阅读全文
posted @ 2015-11-27 20:29 zengzy 阅读(138) 评论(0) 推荐(0)
摘要:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the fol... 阅读全文
posted @ 2015-11-23 22:04 zengzy 阅读(219) 评论(0) 推荐(0)
摘要:一.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 阅读(142) 评论(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 阅读(159) 评论(0) 推荐(0)
摘要:这是使用DFS来解数组类题的典型题目,像求子集,和为sum的k个数也是一个类型 解题步骤: 1:有哪些起点,例如,数组中的每个元素都有可能作为起点,那么用个for循环就可以了。 2:是否允许重复组合 3:处理某个数,判断结果 4:dfs递归 5:还原现场 一:Permutations Given a 阅读全文
posted @ 2015-11-13 12:21 zengzy 阅读(458) 评论(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 阅读(180) 评论(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 阅读(222) 评论(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 阅读(196) 评论(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 阅读(189) 评论(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 阅读(177) 评论(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 阅读(166) 评论(0) 推荐(0)
摘要:一:Search in Sorted Array二分查找,可有重复元素,返回target所在的位置,只需返回其中一个位置,代码中的查找范围为[low,high),左闭右开,否则容易照成死循环。代码:class Solution {public: int search(vector& nums,... 阅读全文
posted @ 2015-11-12 12:21 zengzy 阅读(284) 评论(0) 推荐(0)
摘要:1).2sum1.题意:找出数组中和为target的所有数对2.思路:排序数组,然后用两个指针i、j,一前一后,计算两个指针所指内容的和与target的关系,如果小于target,i右移,如果大于,j左移,否则为其中一个解3.时间复杂度:O(nlgn)+O(n)4.空间:O(1)5.代码: v... 阅读全文
posted @ 2015-11-07 14:28 zengzy 阅读(508) 评论(0) 推荐(2)
摘要:Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjac... 阅读全文
posted @ 2015-11-06 00:34 zengzy 阅读(992) 评论(0) 推荐(0)
摘要:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjace... 阅读全文
posted @ 2015-11-05 22:41 zengzy 阅读(547) 评论(0) 推荐(0)

levels of contents