10 2015 档案

50. Pow(x, n) (INT; Divide-and-Conquer)
摘要:Implement pow(x, n). 思路:二分法,将每次相乘,转化成平方。 阅读全文

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

149. Max Points on a Line (Array; Greedy)
摘要:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 思路:对于某一点来说,在经过该点的直线中选取节点数量最多的直线;对于全局来说,必定是某个局部点满足条 阅读全文

posted @ 2015-10-30 19:23 joannae 阅读(189) 评论(0) 推荐(0)

55. Jump Game (Array; Greedy)
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maxim 阅读全文

posted @ 2015-10-30 19:15 joannae 阅读(207) 评论(0) 推荐(0)

87. Scramble String (String; DP)
摘要:Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representati 阅读全文

posted @ 2015-10-30 18:59 joannae 阅读(285) 评论(0) 推荐(0)

115. Distinct Subsequences (String; DP)
摘要:Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from t 阅读全文

posted @ 2015-10-30 06:29 joannae 阅读(199) 评论(0) 推荐(0)

72. Edit Distance (String; DP)
摘要:Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have 阅读全文

posted @ 2015-10-29 16:50 joannae 阅读(146) 评论(0) 推荐(0)

97. Interleaving String (String; DP)
摘要: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 @ 2015-10-29 08:25 joannae 阅读(174) 评论(0) 推荐(0)

140. Word Break II (String; DP,DFS)
摘要:Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such p 阅读全文

posted @ 2015-10-29 06:47 joannae 阅读(532) 评论(0) 推荐(0)

139. Word Break (String; DP)
摘要:Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For 阅读全文

posted @ 2015-10-28 18:51 joannae 阅读(257) 评论(0) 推荐(0)

120. Triangle(Array; DP)
摘要: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 fo 阅读全文

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

132. Palindrome Partitioning II (String; DP)
摘要:Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning 阅读全文

posted @ 2015-10-23 21:01 joannae 阅读(161) 评论(0) 推荐(0)

91. Decode Ways (Array; DP)
摘要:A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message conta... 阅读全文

posted @ 2015-10-14 21:30 joannae 阅读(205) 评论(0) 推荐(0)

45. Jump Game II (Array; Two-Pointers,Greedy)
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maxim 阅读全文

posted @ 2015-10-14 21:25 joannae 阅读(199) 评论(0) 推荐(0)

70. Climbing Stairs (Array; DP)
摘要:You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb... 阅读全文

posted @ 2015-10-14 18:59 joannae 阅读(148) 评论(0) 推荐(0)

123. Best Time to Buy and Sell Stock III (Array; DP)
摘要:Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may comple 阅读全文

posted @ 2015-10-14 18:55 joannae 阅读(198) 评论(0) 推荐(0)

122. Best Time to Buy and Sell Stock II (Array;Greedy)
摘要:Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may comple 阅读全文

posted @ 2015-10-14 18:45 joannae 阅读(171) 评论(0) 推荐(0)

121. Best Time to Buy and Sell Stock (Array;DP)
摘要:Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction 阅读全文

posted @ 2015-10-14 18:38 joannae 阅读(193) 评论(0) 推荐(0)

38. Count and Say (String; DP)
摘要:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"tw... 阅读全文

posted @ 2015-10-13 19:26 joannae 阅读(211) 评论(0) 推荐(0)

60. Permutation Sequence (String; Math)
摘要:The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order,We get the following sequence 阅读全文

posted @ 2015-10-12 06:29 joannae 阅读(205) 评论(0) 推荐(0)

内存中的堆栈
摘要:函数调用入栈顺序在函数调用时,第一个进栈的是主函数中函数调用后的下一条指令的地址,然后是函数的各个参数。再然后是函数中的局部变量。注意静态变量是不入栈的。Pascal语言中函数参数从左到右入栈的,C语言则从右至左。原因是Pascal语言不支持可变长参数,而C语言支持这种特色。通过栈堆分析可知,自左向... 阅读全文

posted @ 2015-10-10 09:26 joannae 阅读(1326) 评论(0) 推荐(0)

42. Trapping Rain Water (Array,stack; DP)
摘要:Given n non-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. 阅读全文

posted @ 2015-10-09 12:02 joannae 阅读(241) 评论(0) 推荐(0)

84. Largest Rectangle in Histogram (Array, Stack; DP)
摘要:Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the hist 阅读全文

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

85. Maximal Rectangle (Graph; Stack, DP)
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.思路:例如0110111010011101111011111000... 阅读全文

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

134. Gas Station (Array; DP)
摘要:There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it cost 阅读全文

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

53. Maximum Subarray (Array; DP)
摘要: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, 阅读全文

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

36. Valid Sudoku (Array; HashTable)
摘要:Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled wit 阅读全文

posted @ 2015-10-06 13:29 joannae 阅读(235) 评论(0) 推荐(0)

37. Sudoku Solver (Array;Back-Track)
摘要:Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by the character '.'. You may assume that there will be 阅读全文

posted @ 2015-10-06 12:46 joannae 阅读(183) 评论(0) 推荐(0)

52. N-Queens II (Array; Back-Track)
摘要:Follow up for N-Queens problem. Now, instead outputting board configurations, return the total number of distinct solutions. 阅读全文

posted @ 2015-10-06 12:25 joannae 阅读(195) 评论(0) 推荐(0)

51. N-Queens (Array; Back-Track, Bit)
摘要:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all 阅读全文

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

44. Wildcard Matching (String; DP, Back-Track)
摘要:Implement wildcard pattern matching with support for '?' and '*'. *正则表达式的定义: '.' Matches any single character. '*' Matches zero or more of the precedi 阅读全文

posted @ 2015-10-05 19:07 joannae 阅读(177) 评论(0) 推荐(0)

93. Restore IP Addresses(dfs)
摘要:Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example:Given "25525511135", return ["2 阅读全文

posted @ 2015-10-05 09:51 joannae 阅读(243) 评论(0) 推荐(0)

40. Combination Sum II (Back-Track)
摘要:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each num 阅读全文

posted @ 2015-10-05 08:31 joannae 阅读(164) 评论(0) 推荐(0)

39. Combination Sum (Back-Track)
摘要:Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeat 阅读全文

posted @ 2015-10-05 08:26 joannae 阅读(202) 评论(0) 推荐(0)

31. Next Permutation (Array; Math)
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possib 阅读全文

posted @ 2015-10-05 08:18 joannae 阅读(196) 评论(0) 推荐(0)

47. Permutations II (Back-Track, Sort)
摘要:Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2] have the following unique pe 阅读全文

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

46. Permutations (Back-Track,Sort)
摘要:Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1 阅读全文

posted @ 2015-10-05 07:01 joannae 阅读(241) 评论(0) 推荐(0)

77. Combinations (Recursion)
摘要:Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4], [3,4], [2,3],... 阅读全文

posted @ 2015-10-05 06:56 joannae 阅读(198) 评论(0) 推荐(0)

90. Subsets II (Back-Track, DP)
摘要:Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: Elements in a subset must be in non-descending 阅读全文

posted @ 2015-10-05 06:51 joannae 阅读(152) 评论(0) 推荐(0)

78. Subsets (Back-Track, DP)
摘要:Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must 阅读全文

posted @ 2015-10-05 06:44 joannae 阅读(260) 评论(0) 推荐(0)

131. Palindrome Partitioning (Back-Track, DP)
摘要:Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For exampl 阅读全文

posted @ 2015-10-05 06:39 joannae 阅读(197) 评论(0) 推荐(0)

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 阅读(203) 评论(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)

Leetcode catalogue
摘要:1. Array & List 1.1Sort Array的变更操作,好好运用尾指针:88题的end,75题的blueHead 88. Merge Sorted Array (Array) 75. Sort Colors 21. Merge Two Sorted Lists 23. Merge k 阅读全文

posted @ 2015-10-03 19:39 joannae 阅读(190) 评论(0) 推荐(0)

145. Binary Tree Postorder Traversal (Stack, Tree)
摘要:Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, return [3,2,1]. Note: Recursive so 阅读全文

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

144. Binary Tree Preorder Traversal (Tree, Stack)
摘要:Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3... 阅读全文

posted @ 2015-10-03 17:30 joannae 阅读(191) 评论(0) 推荐(0)

114. Flatten Binary Tree to Linked List (Stack, Tree; DFS)
摘要:Given a binary tree, flatten it to a linked list in-place. For example, Given The flattened tree should look like: 法I:递归,前序遍历 法II:迭代 每次循环,找到左子树前序遍历的最后 阅读全文

posted @ 2015-10-03 17:27 joannae 阅读(186) 评论(0) 推荐(0)

146. LRU Cache (List, HashTable)
摘要:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the 阅读全文

posted @ 2015-10-03 16:05 joannae 阅读(256) 评论(0) 推荐(0)

142. Linked List Cycle II (List; Two-Pointers)
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list. Follow up:Can you ... 阅读全文

posted @ 2015-10-03 15:55 joannae 阅读(156) 评论(0) 推荐(0)

141. Linked List Cycle (List; Two-Pointers)
摘要:Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space?思路:采用“快慢指针”查检查链表是否含有环。让一个指针一次走一步,另一个一次走两步... 阅读全文

posted @ 2015-10-03 15:53 joannae 阅读(152) 评论(0) 推荐(0)

125. Valid Palindrome (Array; Two-Pointers)
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal: Pan... 阅读全文

posted @ 2015-10-03 15:41 joannae 阅读(154) 评论(0) 推荐(0)

135. Candy(Array; Greedy)
摘要:There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following re 阅读全文

posted @ 2015-10-03 15:34 joannae 阅读(185) 评论(0) 推荐(0)

69. Sqrt(x) (Divide-and-Conquer)
摘要:Implement int sqrt(int x). Compute and return the square root of x. 注意: 计算平方的时候可能会溢出,所以mid要定义为long 另外,二分法初始上限不可能超过n/2+1 阅读全文

posted @ 2015-10-03 14:25 joannae 阅读(193) 评论(0) 推荐(0)

109. Convert Sorted List to Binary Search Tree (List; Divide-and-Conquer, dfs)
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 也可以通过引用传递,这样就不需要先初始化。 注意,NULL是一个宏定义 #def 阅读全文

posted @ 2015-10-03 14:15 joannae 阅读(181) 评论(0) 推荐(0)

108.Convert Sorted Array to Binary Search Tree(Array; Divide-and-Conquer, dfs)
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路:使用二分法,将list的中间节点作为根节点,然后分别处理list左半边及右半边,以此递归。struc... 阅读全文

posted @ 2015-10-03 14:10 joannae 阅读(251) 评论(0) 推荐(0)

34. Search for a Range (Array; Divide-and-Conquer)
摘要: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 or 阅读全文

posted @ 2015-10-03 11:46 joannae 阅读(177) 评论(0) 推荐(0)

35. Search Insert Position (Array; Divide-and-Conquer)
摘要: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-10-03 11:37 joannae 阅读(171) 评论(0) 推荐(0)

82. Remove Duplicates from Sorted List II (List)
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example,Given 1->2... 阅读全文

posted @ 2015-10-03 11:33 joannae 阅读(208) 评论(0) 推荐(0)

83. Remove Duplicates from Sorted List (List)
摘要:Given a sorted linked list, delete all duplicates such that each element appear only once. For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3,... 阅读全文

posted @ 2015-10-03 11:31 joannae 阅读(165) 评论(0) 推荐(0)

80. Remove Duplicates from Sorted Array II (Array)
摘要:Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For example, Given sorted array nums = [1,1,1,2,2,3], Your function s 阅读全文

posted @ 2015-10-03 11:30 joannae 阅读(124) 评论(0) 推荐(0)

143. Reorder List(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 @ 2015-10-03 11:22 joannae 阅读(225) 评论(0) 推荐(0)

61. Rotate List(List)
摘要:Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->... 阅读全文

posted @ 2015-10-03 10:57 joannae 阅读(150) 评论(0) 推荐(0)

92. Reverse Linked List II (List)
摘要:Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2 阅读全文

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

86. Partition List (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 o... 阅读全文

posted @ 2015-10-03 10:29 joannae 阅读(142) 评论(0) 推荐(0)

148. Sort List (List)
摘要:Sort a linked list in O(n log n) time using constant space complexity. 法I:快排。快排的难点在于切分序列。从头扫描,碰到>=target的元素,停止;从第二个字串扫描,碰到<=target的元素停止;交换这两个元素。这样的好处是 阅读全文

posted @ 2015-10-03 09:41 joannae 阅读(188) 评论(0) 推荐(0)

147. Insertion Sort List (List)
摘要:Sort a linked list using insertion sort. 阅读全文

posted @ 2015-10-03 09:39 joannae 阅读(152) 评论(0) 推荐(0)

128. Longest Consecutive Sequence (HashTable)
摘要: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 long 阅读全文

posted @ 2015-10-03 09:28 joannae 阅读(222) 评论(0) 推荐(0)

75. Sort Colors (Array)
摘要:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, ... 阅读全文

posted @ 2015-10-03 08:34 joannae 阅读(200) 评论(0) 推荐(0)

88. Merge Sorted Array (Array)
摘要:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size tha... 阅读全文

posted @ 2015-10-03 07:56 joannae 阅读(151) 评论(0) 推荐(0)

进制转换
摘要:十六进制,十进制,二进制的转换,转换结果放在一个string中首先,十进制转到几进制,就是除以几的余数,先得到的放在低位,直至结果为0其次string转成int:Integer.parseInt(s); 也可以通过string得到char,在通过与'0'相减比较得到intint转成string: S... 阅读全文

posted @ 2015-10-01 15:01 joannae 阅读(164) 评论(0) 推荐(0)

JRE,JVM,JDK
摘要:JRE,JVM,JDK的关系。JRE(Java Runtime Environment)java运行环境,我们可以把它看成是一个操作系统。也就是说JRE提供了Java执行的软件平台。JVM (Java Virtual Machine)Java虚拟机。所谓“虚拟机”顾名思义就是模拟出来的东西。JVM就... 阅读全文

posted @ 2015-10-01 14:35 joannae 阅读(170) 评论(0) 推荐(0)

将中缀式转化为逆波兰式 (栈)
摘要:逆波兰式:Reverse Polish notation,RPN,,也叫后缀表达式,将运算符写在操作数之后数据结构:两个栈S1和S2。S1临时存储运算符,S2存储最终结果。算法:(1)若取出的字符是操作数,则分析出完整的运算数,该操作数直接送入S2栈(2)若取出的字符是运算符,则将该运算符与S1栈栈... 阅读全文

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

字符串匹配——C++使用Regex
摘要:需要#include匹配regex_match ("subject", std::regex("(sub)(.*)")//结果返回true主要regex_match需要匹配源字符串的每个字符,这点与regex_search不同查找返回一个匹配项 const regex pattern("(\\... 阅读全文

posted @ 2015-10-01 10:59 joannae 阅读(5998) 评论(0) 推荐(0)

线段树(segment tree)
摘要:线段树是一棵二叉树,记为T(a, b),参数a,b表示区间[a,b],其中b-a称为区间的长度,记为L。数据结构:struct Node{ int left,right; //区间左右值 Node *leftchild; Node *rightchild; };... 阅读全文

posted @ 2015-10-01 10:53 joannae 阅读(233) 评论(0) 推荐(0)

平衡二叉树之伸展树
摘要:伸展树(Splay Tree),或者叫自适应查找树,插入、查找和删除操作的时间都为O(logn)。伸展树的目的是使被查频率高的那些条目就应当经常处于靠近树根的位置。它的做法是在每次查找后,将被查找的节点splay到根节点。使用伸展树需要符合90-10法则:在实际情况中,90%的访问发生在10%的数据... 阅读全文

posted @ 2015-10-01 10:26 joannae 阅读(747) 评论(0) 推荐(0)

平衡二叉树之RB树
摘要:RB树(红黑树)并不追求“完全平衡”——它只要求部分地达到平衡要求,降低了对旋转的要求,从而提高了性能。由于它的设计,任何不平衡都会在三次旋转之内解决。典型的用途是实现关联数组(如C++中的map和set) 红黑树满足以下特性: 1)每个结点要么是红的,要么是黑的。 2)根结点是黑的。 3)每个叶结 阅读全文

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

平衡二叉树之AVL树
摘要:AVL树(命名来源于作者姓名,Adelson-Velskii和Landis),即平衡二叉树,满足以下的条件:1)它的左子树和右子树都是AVL树2)左子树和右子树的高度差不能超过1从条件1可能看出是个递归定义。AVL树中任何节点的两个儿子子树的高度最大差别为一,所以它也被称为高度平衡树。AVL树插入节... 阅读全文

posted @ 2015-10-01 10:09 joannae 阅读(240) 评论(0) 推荐(0)

实现哈希表
摘要:哈希表原理:输入(key, value) -> 通过散列函数生成hashkey -> 将(key,value)放入hashkey对应的bucket 散列函数满足以下的条件:1、对输入值运算,得到一个固定长度的摘要(Hash value);2、不同的输入值可能对应同样的输出值;3、散列函数的输出值尽量 阅读全文

posted @ 2015-10-01 09:57 joannae 阅读(383) 评论(0) 推荐(0)

经典贪心算法(哈夫曼算法,Dijstra单源最短路径算法,最小费用最大流)
摘要:哈夫曼编码与哈夫曼算法哈弗曼编码的目的是,如何用更短的bit来编码数据。通过变长编码压缩编码长度。我们知道普通的编码都是定长的,比如常用的ASCII编码,每个字符都是8个bit。但在很多情况下,数据文件中的字符出现的概率是不均匀的,比如在一篇英语文章中,字母“E”出现的频率最高,“Z”最低,这时我们... 阅读全文

posted @ 2015-10-01 09:25 joannae 阅读(14654) 评论(2) 推荐(0)

NPC问题及其解决方法(回溯法、动态规划、贪心法、深度优先遍历)
摘要:NP问题(Non-deterministic Polynomial ):多项式复杂程度的非确定性问题,这些问题无法根据公式直接地计算出来。比如,找大质数的问题(有没有一个公式,你一套公式,就可以一步步推算出来,下一个质数应该是多少呢?这样的公式是没有的);再比如,大的合数分解质因数的问题(有没有一个... 阅读全文

posted @ 2015-10-01 08:49 joannae 阅读(8472) 评论(0) 推荐(0)

导航