随笔分类 -  leetcode

Median of Two Sorted Arrays
摘要:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be 阅读全文

posted @ 2014-09-06 16:50 bug睡的略爽 阅读(145) 评论(0) 推荐(0)

Minimum Window Substring
摘要:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example,S = "ADOBECOD 阅读全文

posted @ 2014-09-05 10:18 bug睡的略爽 阅读(191) 评论(0) 推荐(0)

Partition List
摘要:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the 阅读全文

posted @ 2014-09-04 10:50 bug睡的略爽 阅读(146) 评论(0) 推荐(0)

Reorder List
摘要:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' values. For 阅读全文

posted @ 2014-09-04 10:31 bug睡的略爽 阅读(142) 评论(0) 推荐(0)

Longest Common Prefix
摘要:Write a function to find the longest common prefix string amongst an array of strings. 这题很简单,直接依次比较即可,代码如下: 1 class Solution { 2 public: 3 string long 阅读全文

posted @ 2014-09-04 10:04 bug睡的略爽 阅读(148) 评论(0) 推荐(0)

Two Sum 系列
摘要:Two Sum 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 t 阅读全文

posted @ 2014-09-03 21:17 bug睡的略爽 阅读(185) 评论(0) 推荐(0)

Search in Rotated Sorted Array
摘要:Search 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 5 6 7 0 阅读全文

posted @ 2014-09-03 16:32 bug睡的略爽 阅读(133) 评论(0) 推荐(0)

Interleaving String
摘要:Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = "aabcc",s2 = "dbbca", When s3 = "aadbbcbcac", ret 阅读全文

posted @ 2014-09-03 15:47 bug睡的略爽 阅读(156) 评论(0) 推荐(0)

Longest Valid Parentheses
摘要:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. For "(()", the lo 阅读全文

posted @ 2014-09-03 10:40 bug睡的略爽 阅读(234) 评论(3) 推荐(1)

Valid Parentheses
摘要:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the 阅读全文

posted @ 2014-09-02 11:21 bug睡的略爽 阅读(145) 评论(0) 推荐(0)

Generate Parentheses
摘要:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: " 阅读全文

posted @ 2014-09-02 09:58 bug睡的略爽 阅读(403) 评论(0) 推荐(0)

Symmetric Tree
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / 阅读全文

posted @ 2014-08-28 19:49 bug睡的略爽 阅读(138) 评论(0) 推荐(0)

Validate Binary Search Tree
摘要:Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only 阅读全文

posted @ 2014-08-28 19:38 bug睡的略爽 阅读(133) 评论(0) 推荐(0)

Recover Binary Search Tree
摘要: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 i 阅读全文

posted @ 2014-08-28 18:31 bug睡的略爽 阅读(223) 评论(0) 推荐(0)

Subsets系列
摘要: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 阅读全文

posted @ 2014-08-28 17:05 bug睡的略爽 阅读(195) 评论(0) 推荐(0)

Convert Sorted Array to Binary Search Tree & Convert Sorted List to Binary Search Tree
摘要:Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 方法:将有序数组转 阅读全文

posted @ 2014-08-27 22:14 bug睡的略爽 阅读(149) 评论(0) 推荐(0)

Balanced Binary Tree
摘要:Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the dept 阅读全文

posted @ 2014-08-26 17:15 bug睡的略爽 阅读(150) 评论(0) 推荐(0)

Minimum Depth of Binary Tree & Maximum Depth of Binary Tree
摘要:Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest l 阅读全文

posted @ 2014-08-26 16:47 bug睡的略爽 阅读(122) 评论(0) 推荐(0)

Flatten Binary Tree to Linked List
摘要:Flatten Binary Tree to Linked List Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tr 阅读全文

posted @ 2014-08-26 16:30 bug睡的略爽 阅读(137) 评论(0) 推荐(0)

Path Sum系列
摘要:Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the giv 阅读全文

posted @ 2014-08-26 16:23 bug睡的略爽 阅读(177) 评论(0) 推荐(0)

导航