随笔分类 -  Leetcode (C++)

上一页 1 ··· 3 4 5 6 7 8 9 10 下一页

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 阅读(184) 评论(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 阅读(150) 评论(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 阅读(184) 评论(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 阅读(223) 评论(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 阅读(190) 评论(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 阅读(184) 评论(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 阅读(255) 评论(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 阅读(153) 评论(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 阅读(151) 评论(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 阅读(183) 评论(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 阅读(192) 评论(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 阅读(180) 评论(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 阅读(249) 评论(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 阅读(173) 评论(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 阅读(207) 评论(0) 推荐(0)

上一页 1 ··· 3 4 5 6 7 8 9 10 下一页

导航