2015年10月4日

41. First Missing Positive (HashTable)

摘要: Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2. Your algorithm s 阅读全文

posted @ 2015-10-04 20:18 joannae 阅读(169) 评论(0) 推荐(0)

49. Group Anagrams (string, HashTable)

摘要: Given an array of strings, group anagrams together. For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return: [ ["ate", "eat","tea"], [" 阅读全文

posted @ 2015-10-04 19:38 joannae 阅读(163) 评论(0) 推荐(0)

76. Minimum Window Substring (String, Map)

摘要: 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="ADOBECODEBA... 阅读全文

posted @ 2015-10-04 19:01 joannae 阅读(168) 评论(0) 推荐(0)

63. Unique Paths II (Graph; DP)

摘要: Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space i... 阅读全文

posted @ 2015-10-04 18:35 joannae 阅读(149) 评论(0) 推荐(0)

62. Unique Paths (Graph; DP)

摘要: A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point ... 阅读全文

posted @ 2015-10-04 18:33 joannae 阅读(169) 评论(0) 推荐(0)

64. Minimum Path Sum (Graph; DP)

摘要: 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-10-04 18:31 joannae 阅读(202) 评论(0) 推荐(0)

126. Word Ladder II( Queue; BFS)

摘要: Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such th 阅读全文

posted @ 2015-10-04 17:34 joannae 阅读(275) 评论(0) 推荐(0)

130. Surrounded Regions (Graph; DFS)

摘要: Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded ... 阅读全文

posted @ 2015-10-04 16:57 joannae 阅读(218) 评论(0) 推荐(0)

138. Copy List with Random Pointer (Graph, Map; DFS)

摘要: 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 @ 2015-10-04 16:41 joannae 阅读(218) 评论(0) 推荐(0)

133. Clone Graph (Graph, Map; DFS)

摘要: Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's undirected graph serialization: Nodes are labeled 阅读全文

posted @ 2015-10-04 16:37 joannae 阅读(203) 评论(0) 推荐(0)

73. Set Matrix Zeroes (Array)

摘要: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Follow up: Did you use extra space? A straight forward s 阅读全文

posted @ 2015-10-04 16:21 joannae 阅读(186) 评论(0) 推荐(0)

79. Word Search (Array; DFS,Back-Track)

摘要: 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 "adjac 阅读全文

posted @ 2015-10-04 16:15 joannae 阅读(169) 评论(0) 推荐(0)

59. Spiral Matrix II (Array)

摘要: Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example, Given n = 3, You should return the follow 阅读全文

posted @ 2015-10-04 15:59 joannae 阅读(143) 评论(0) 推荐(0)

54. Spiral Matrix (Graph)

摘要: Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example,Given the following matrix:[ [ 1,... 阅读全文

posted @ 2015-10-04 15:56 joannae 阅读(195) 评论(0) 推荐(0)

74. Search a 2D Matrix (Graph; Divide-and-Conquer)

摘要: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted f 阅读全文

posted @ 2015-10-04 15:51 joannae 阅读(166) 评论(0) 推荐(0)

48. Rotate Image (Array)

摘要: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up: Could you do this in-place? 阅读全文

posted @ 2015-10-04 15:46 joannae 阅读(133) 评论(0) 推荐(0)

119. Pascal's Triangle II (Graph; WFS)

摘要: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use... 阅读全文

posted @ 2015-10-04 15:43 joannae 阅读(143) 评论(0) 推荐(0)

118. Pascal's Triangle (Array)

摘要: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return 阅读全文

posted @ 2015-10-04 15:27 joannae 阅读(192) 评论(0) 推荐(0)

127. Word Ladder (Tree, Queue; WFS)

摘要: Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, 阅读全文

posted @ 2015-10-04 15:21 joannae 阅读(372) 评论(0) 推荐(0)

117. Populating Next Right Pointers in Each Node II (Tree; WFS)

摘要: Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution stil... 阅读全文

posted @ 2015-10-04 14:58 joannae 阅读(173) 评论(0) 推荐(0)

116. Populating Next Right Pointers in Each Node (Tree; WFS)

摘要: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointe... 阅读全文

posted @ 2015-10-04 14:54 joannae 阅读(185) 评论(0) 推荐(0)

107. Binary Tree Level Order Traversal II(Tree, WFS)

摘要: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For ... 阅读全文

posted @ 2015-10-04 14:49 joannae 阅读(176) 评论(0) 推荐(0)

106. Construct Binary Tree from Inorder and Postorder Traversal (Tree; DFS)

摘要: Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.struct TreeNod... 阅读全文

posted @ 2015-10-04 14:33 joannae 阅读(157) 评论(0) 推荐(0)

105. Construct Binary Tree from Preorder and Inorder Traversal (Tree; DFS)

摘要: Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.class Solution ... 阅读全文

posted @ 2015-10-04 14:24 joannae 阅读(154) 评论(0) 推荐(0)

101. Symmetric Tree (Tree, Queue; DFS, WFS)

摘要: 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 @ 2015-10-04 14:11 joannae 阅读(312) 评论(0) 推荐(0)

95. Unique Binary Search Trees II (Tree; DFS)

摘要: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example, Given n = 3, your program should return al 阅读全文

posted @ 2015-10-04 12:22 joannae 阅读(294) 评论(0) 推荐(0)

96. Unique Binary Search Trees (Tree; DP)

摘要: Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST 阅读全文

posted @ 2015-10-04 11:49 joannae 阅读(219) 评论(0) 推荐(0)

110. Balanced Binary Tree (Tree; DFS)

摘要: 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 depth... 阅读全文

posted @ 2015-10-04 11:38 joannae 阅读(160) 评论(0) 推荐(0)

104. Maximum Depth of Binary Tree (Tree; DFS)

摘要: Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le... 阅读全文

posted @ 2015-10-04 11:35 joannae 阅读(188) 评论(0) 推荐(0)

111. Minimum Depth of Binary Tree (Tree; DFS)

摘要: 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 le... 阅读全文

posted @ 2015-10-04 11:34 joannae 阅读(221) 评论(0) 推荐(0)

124. Binary Tree Maximum Path Sum (Tree; DFS)

摘要: Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from some starting node to any node in th 阅读全文

posted @ 2015-10-04 11:17 joannae 阅读(230) 评论(0) 推荐(0)

99. Recover Binary Search Tree (Tree; DFS)

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

posted @ 2015-10-04 10:35 joannae 阅读(183) 评论(0) 推荐(0)

129. Sum Root to Leaf Numbers(Tree; DFS)

摘要: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which... 阅读全文

posted @ 2015-10-04 10:22 joannae 阅读(162) 评论(0) 推荐(0)

113. Path Sum II (Tree; DFS)

摘要: Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum ... 阅读全文

posted @ 2015-10-04 10:20 joannae 阅读(186) 评论(0) 推荐(0)

112. Path Sum (Tree; DFS)

摘要: 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 given sum.Fo... 阅读全文

posted @ 2015-10-04 10:18 joannae 阅读(152) 评论(0) 推荐(0)

150. Evaluate Reverse Polish Notation (Stack)

摘要: Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another ex... 阅读全文

posted @ 2015-10-04 10:11 joannae 阅读(161) 评论(0) 推荐(0)

32. Longest Valid Parentheses (Stack; DP)

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

posted @ 2015-10-04 10:05 joannae 阅读(186) 评论(0) 推荐(0)

71. Simplify Path (Stack)

摘要: Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c" 注意:题目中已限定是abso 阅读全文

posted @ 2015-10-04 07:59 joannae 阅读(187) 评论(0) 推荐(0)

导航