随笔分类 -  Leetcode

摘要:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the valu... 阅读全文
posted @ 2014-11-26 17:24 Jessica程序猿 阅读(398) 评论(0) 推荐(0)
摘要:Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.参考:http://blog.csdn.net/doc_sgl/article/details/17103... 阅读全文
posted @ 2014-11-26 16:22 Jessica程序猿 阅读(172) 评论(0) 推荐(0)
摘要:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is ... 阅读全文
posted @ 2014-11-26 10:50 Jessica程序猿 阅读(226) 评论(0) 推荐(0)
摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy ... 阅读全文
posted @ 2014-11-26 09:27 Jessica程序猿 阅读(169) 评论(0) 推荐(0)
摘要:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.参考:http://www.cnblogs.com/AnnieKim/ar... 阅读全文
posted @ 2014-11-25 22:39 Jessica程序猿 阅读(227) 评论(0) 推荐(0)
摘要:There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[... 阅读全文
posted @ 2014-11-25 21:47 Jessica程序猿 阅读(220) 评论(0) 推荐(0)
摘要:Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 uni... 阅读全文
posted @ 2014-11-25 20:01 Jessica程序猿 阅读(199) 评论(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 @ 2014-11-25 17:23 Jessica程序猿 阅读(134) 评论(0) 推荐(0)
摘要:Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of ... 阅读全文
posted @ 2014-11-25 13:59 Jessica程序猿 阅读(154) 评论(0) 推荐(0)
摘要:Given an arraySofnintegers, find three integers inSsuch that the sum is closest to a given number, target. Return the sum of the three integers. You m... 阅读全文
posted @ 2014-11-25 13:02 Jessica程序猿 阅读(147) 评论(0) 推荐(0)
摘要:Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:Elemen... 阅读全文
posted @ 2014-11-25 11:31 Jessica程序猿 阅读(187) 评论(0) 推荐(0)
摘要:Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest... 阅读全文
posted @ 2014-11-24 22:13 Jessica程序猿 阅读(163) 评论(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 @ 2014-11-24 21:20 Jessica程序猿 阅读(175) 评论(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 @ 2014-11-24 20:10 Jessica程序猿 阅读(185) 评论(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].思路:首先以start排序,... 阅读全文
posted @ 2014-11-24 18:24 Jessica程序猿 阅读(205) 评论(0) 推荐(0)
摘要:Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:开始做过两两合并的链表,此时做k路合并,即将k个链表进行合并,可以先将这k个链表进行两两合并,知道合并... 阅读全文
posted @ 2014-11-24 17:02 Jessica程序猿 阅读(196) 评论(0) 推荐(0)
摘要:Implementint sqrt(int x).Compute and return the square root ofx.这里给出两种实现方法:一是二分搜索,二是牛顿迭代法。1. 二分搜索对于一个非负数n,它的平方根不会小于大于(n/2+1)。在[0, n/2+1]这个范围内可以进行二分搜索,... 阅读全文
posted @ 2014-11-24 15:59 Jessica程序猿 阅读(477) 评论(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 ru... 阅读全文
posted @ 2014-11-24 12:34 Jessica程序猿 阅读(155) 评论(0) 推荐(0)
摘要:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.C++实现代码:#inclu... 阅读全文
posted @ 2014-11-24 10:09 Jessica程序猿 阅读(192) 评论(0) 推荐(0)
摘要:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.提交成功的代码:C++实现:#... 阅读全文
posted @ 2014-11-24 09:59 Jessica程序猿 阅读(241) 评论(0) 推荐(0)