LeetCode
文章平均质量分 67
笑傲1024
这个作者很懒,什么都没留下…
展开
-
【LeetCode】-Sort List
Sort a linked list in O(n log n) time using constant space complexity.原创 2014-09-21 21:48:03 · 155 阅读 · 0 评论 -
【LeetCode】-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 example,Given {1,2,3,4}, reorder it t原创 2014-09-22 16:19:28 · 189 阅读 · 0 评论 -
【LeetCode】-Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].原创 2014-09-22 15:59:40 · 161 阅读 · 0 评论 -
【LeetCode】-Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".原创 2014-10-15 10:10:04 · 181 阅读 · 0 评论 -
【LeetCode】-Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2014-09-24 17:41:58 · 180 阅读 · 0 评论 -
【LeetCode】-Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples:原创 2014-09-21 19:02:34 · 204 阅读 · 0 评论 -
【LeetCode】-Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20原创 2014-09-24 15:26:36 · 194 阅读 · 0 评论 -
【LeetCode】-Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree./** * Definition for binary tree * public class Tree原创 2014-09-24 10:42:29 · 203 阅读 · 0 评论 -
【LeetCode】-Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solution is tri原创 2014-09-22 21:54:51 · 212 阅读 · 0 评论 -
【LeetCode】-Merge Intervals
Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].原创 2014-10-20 22:14:42 · 259 阅读 · 0 评论 -
【LeetCode】-Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.E原创 2014-10-20 22:16:52 · 224 阅读 · 0 评论 -
【LeetCode】-Remove Duplicates from Sorted List II
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->3->3->4->4->5, return 1->2->5.Given 1->原创 2014-09-24 16:32:21 · 285 阅读 · 0 评论 -
【LeetCode】-LRU Cache
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 value (will always be positive) of the key if原创 2014-09-21 22:31:07 · 327 阅读 · 0 评论 -
【LeetCode】-Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * public cla原创 2014-09-22 17:24:28 · 167 阅读 · 0 评论 -
【LeetCode】-Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.原创 2014-09-22 17:17:10 · 228 阅读 · 0 评论 -
【LeetCode】-Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]原创 2014-09-22 17:05:11 · 223 阅读 · 0 评论 -
【LeetCode】-Max Points on a Line
Max Points on a Line原创 2014-09-21 21:31:11 · 263 阅读 · 0 评论 -
【LeetCode】-Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the原创 2014-10-15 15:47:02 · 245 阅读 · 0 评论 -
【LeetCode】-Copy List with Random Pointer
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 of the list.原创 2014-10-14 22:51:53 · 256 阅读 · 0 评论 -
【LeetCode】-Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.原创 2014-09-23 23:08:23 · 217 阅读 · 0 评论 -
【LeetCode】-Best Time to Buy and Sell Stock II
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 complete as many transactions as you like (ie, buy on原创 2014-09-22 16:57:40 · 181 阅读 · 0 评论 -
【LeetCode】-Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?原创 2014-09-22 16:34:25 · 184 阅读 · 0 评论 -
【LeetCode】-Binary Tree Preorder Traversal
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].原创 2014-09-22 16:10:44 · 167 阅读 · 0 评论 -
【LeetCode】-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 1 2).You are given a target value to search. If found in the array retur原创 2014-10-15 15:23:02 · 194 阅读 · 0 评论 -
【LeetCode】-Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as原创 2014-10-22 13:00:52 · 171 阅读 · 0 评论