随笔分类 -  leetcode

摘要:There are two sorted arraysnums1andnums2of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should... 阅读全文
posted @ 2015-07-29 15:40 鸭子船长 阅读(114) 评论(0) 推荐(0)
摘要:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu... 阅读全文
posted @ 2015-07-29 10:39 鸭子船长 阅读(175) 评论(0) 推荐(0)
摘要:A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you aregiven... 阅读全文
posted @ 2015-07-29 00:42 鸭子船长 阅读(189) 评论(0) 推荐(0)
摘要:Given an array of integers, find out whether there are two distinct indicesiandjin the array such that the difference betweennums[i]andnums[j]is at mo... 阅读全文
posted @ 2015-07-28 10:52 鸭子船长 阅读(432) 评论(0) 推荐(0)
摘要: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 @ 2015-07-24 16:39 鸭子船长 阅读(166) 评论(0) 推荐(0)
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matr... 阅读全文
posted @ 2015-07-23 12:35 鸭子船长 阅读(151) 评论(0) 推荐(0)
摘要:Given acompletebinary tree, count the number of nodes.Definition of a complete binary tree fromWikipedia:In a complete binary tree every level, except... 阅读全文
posted @ 2015-07-23 12:34 鸭子船长 阅读(174) 评论(0) 推荐(0)
摘要:Find the total area covered by tworectilinearrectangles in a2Dplane.Each rectangle is defined by its bottom left corner and top right corner as shown ... 阅读全文
posted @ 2015-07-23 12:33 鸭子船长 阅读(156) 评论(0) 推荐(0)
摘要:Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top()... 阅读全文
posted @ 2015-07-23 12:32 鸭子船长 阅读(175) 评论(0) 推荐(0)
摘要:Implement a basic calculator to evaluate a simple expression string.The expression string may contain open(and closing parentheses), the plus+or minus... 阅读全文
posted @ 2015-07-23 12:32 鸭子船长 阅读(156) 评论(0) 推荐(0)
摘要:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired bythis... 阅读全文
posted @ 2015-07-23 12:31 鸭子船长 阅读(214) 评论(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"]. 1 class ... 阅读全文
posted @ 2015-07-23 12:30 鸭子船长 阅读(163) 评论(0) 推荐(0)
摘要:Implement a basic calculator to evaluate a simple expression string.The expression string contains onlynon-negativeintegers,+,-,*,/operators and empty... 阅读全文
posted @ 2015-07-23 12:30 鸭子船长 阅读(169) 评论(0) 推荐(0)
摘要:Given an integer array of sizen, find all elements that appear more than⌊ n/3 ⌋times. The algorithm should run in linear time and in O(1) space.Hint:H... 阅读全文
posted @ 2015-07-23 12:29 鸭子船长 阅读(207) 评论(0) 推荐(0)
摘要:Given a binary search tree, write a functionkthSmallestto find thekth smallest element in it.Note:You may assume k is always valid, 1 ≤ k ≤ BST's tota... 阅读全文
posted @ 2015-07-23 12:28 鸭子船长 阅读(214) 评论(0) 推荐(0)
摘要:Given an integer, write a function to determine if it is a power of two.1 bool isPowerOfTwo(int n) {2 if(n<=0)3 return false;4 if(n&(n-1... 阅读全文
posted @ 2015-07-23 12:27 鸭子船长 阅读(157) 评论(0) 推荐(0)
摘要:Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6... 阅读全文
posted @ 2015-07-23 12:26 鸭子船长 阅读(165) 评论(0) 推荐(0)
摘要:Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front o... 阅读全文
posted @ 2015-07-23 12:26 鸭子船长 阅读(157) 评论(0) 推荐(0)
摘要:Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space? 1 /** 2 * Definition for singly-li... 阅读全文
posted @ 2015-07-23 12:25 鸭子船长 阅读(237) 评论(0) 推荐(0)
摘要:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: ... 阅读全文
posted @ 2015-07-23 12:24 鸭子船长 阅读(180) 评论(0) 推荐(0)