leetcode
BurningWall
这个作者很懒,什么都没留下…
展开
-
leetcode 刷题之路 55 Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".二进制字符串xiang原创 2014-08-09 01:43:04 · 578 阅读 · 0 评论 -
leetcode 刷题之路 70 earch Insert Position 二分查找插入位置
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 order.You may assume no duplicates in the array.原创 2014-08-10 15:46:55 · 837 阅读 · 0 评论 -
leetcode 刷题之路 57 Subsets II
Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain dupli原创 2014-08-09 16:29:11 · 560 阅读 · 0 评论 -
leetcode 刷题之路 66 Path Sum II
给定一个二叉树和数字sum,输出二叉树中从根节点到叶子节点所有路径中和等于sum的路径。原创 2014-08-10 10:25:08 · 759 阅读 · 0 评论 -
leetcode 刷题之路 68 Gas Station
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 costs cost[i] of gas to travel from station i to原创 2014-08-10 13:17:54 · 739 阅读 · 0 评论 -
leetcode 刷题之路 74 Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.从前序遍历结果和中序遍历结果中原创 2014-08-10 18:26:02 · 626 阅读 · 0 评论 -
leetcode 刷题之路 61 Sort List
Sort a linked list in O(n log n) time using constant space complexity.题目要求,对链表进行排序,要求时间buzad原创 2014-08-09 20:45:57 · 540 阅读 · 0 评论 -
leetcode 刷题之路 63 Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).zigzag层序遍历树For example:Given binary原创 2014-08-09 22:05:08 · 727 阅读 · 0 评论 -
leetcode 刷题之路 65 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 / \ / \3 4 4 3But the f原创 2014-08-09 23:50:24 · 550 阅读 · 0 评论 -
leetcode 刷题之路 75 Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.用vector表示一个数,在这个数上j原创 2014-08-10 19:25:32 · 898 阅读 · 0 评论 -
leetcode 刷题之路 69 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 6The flattened tree should look like: 1原创 2014-08-10 14:36:00 · 475 阅读 · 0 评论 -
leetcode 刷题之路 73 Best Time to Buy and Sell Stock III
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 at most two transactions.Note:You ma原创 2014-08-10 17:55:39 · 669 阅读 · 0 评论 -
leetcode 刷题之路 50 Unique Binary Search Trees II
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 all 5 unique BST's shown below. 1 3原创 2014-08-07 22:26:06 · 494 阅读 · 0 评论 -
leetcode 刷题之路 54 Jump Game
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 maximum jump length at that position.Determine i原创 2014-08-09 01:23:35 · 516 阅读 · 0 评论 -
leetcode 刷题之路 49 Unique Binary Search Trees
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's. 1 3 3 2 1 \原创 2014-08-07 19:35:31 · 460 阅读 · 0 评论 -
leetcode 刷题之路 62 Maximum Depth of Binary Tree
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 leaf node.求树的最大深度。树的最大深度d原创 2014-08-09 20:56:36 · 504 阅读 · 0 评论 -
leetcode 刷题之路 71 Best Time to Buy and Sell Stock
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 (ie, buy one and sell one share of the stock),原创 2014-08-10 16:00:11 · 565 阅读 · 0 评论 -
leetcode 刷题之路 72 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-08-10 16:32:26 · 555 阅读 · 0 评论 -
leetcode 刷题之路 56 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 must not contain duplicate subsets.For exa原创 2014-08-09 15:51:46 · 1025 阅读 · 0 评论 -
leetcode 刷题之路 60 Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321对一个整数进行原创 2014-08-09 19:49:00 · 755 阅读 · 1 评论 -
leetcode 刷题之路 64 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.给出二叉树的中序遍历和后序遍历结果,恢复出二叉树。后序遍历序列的最后一个元素值是二叉树的根节点的值,查找原创 2014-08-09 23:06:54 · 767 阅读 · 0 评论 -
leetcode 刷题之路 59 Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?原创 2014-08-09 19:42:27 · 506 阅读 · 0 评论 -
leetcode 刷题之路 67 Reverse Linked List II
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->5->NULL.Note:Given m, n satisfy t原创 2014-08-10 11:06:44 · 453 阅读 · 0 评论 -
leetcode 刷题之路 84 Single Number II
给定一个包含n个整数的数组,除了一个数出现一次外所有的整数均出现三次,找出这个只出现一次的整数。原创 2014-08-13 13:46:36 · 950 阅读 · 0 评论 -
leetcode 刷题之路 87 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-08-13 16:17:59 · 759 阅读 · 0 评论 -
leetcode 刷题之路 90 Sort Colors
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, white and blue.Here, we will use the integers原创 2014-08-13 21:29:31 · 859 阅读 · 0 评论 -
leetcode 刷题之路 86 Remove Element
给定一个数组和一个数字,删除数组中相同的数字并返回数组的新长度。原创 2014-08-13 14:24:29 · 956 阅读 · 0 评论 -
leetcode 刷题之路 85 Merge Two Sorted Lists
erge 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.合并两个有序链表,合并后的链表仍然有序。原创 2014-08-13 15:34:45 · 743 阅读 · 0 评论 -
leetcode 刷题之路 91 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-08-13 21:38:55 · 709 阅读 · 0 评论 -
leetcode 刷题之路 92 Climbing Stairs
一个台阶总共有n级,如果一次可以跳1级,也可以跳2级,求总共有多少总跳法。原创 2014-08-16 20:46:56 · 1227 阅读 · 1 评论 -
leetcode 刷题之路 93 Merge k Sorted Lists
将k个有序链表合并成一个有序链表。原创 2014-08-16 21:02:17 · 723 阅读 · 0 评论 -
leetcode 刷题之路 94 N-Queens
非常经典的N皇后问题:在一个N*N的棋盘上放置N个皇后,每行一个并使其不能互相攻击(同一行、同一列、同一对角线上的皇后都会自动攻击)。原创 2014-08-17 10:51:18 · 844 阅读 · 0 评论 -
leetcode 刷题之路 82 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 original relative order of the nodes in each of原创 2014-08-13 13:18:56 · 894 阅读 · 0 评论 -
leetcode 刷题报告 80 Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using e原创 2014-08-12 20:03:16 · 613 阅读 · 0 评论 -
leetcode 刷题之路 77 Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1原创 2014-08-11 17:21:29 · 971 阅读 · 0 评论 -
leetcode 刷题之路 76 Remove Duplicates from Sorted 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, return 1->2->3.删除排序链表中重复的节点,删除操作原创 2014-08-11 15:47:19 · 753 阅读 · 0 评论 -
leetcode 刷题之路 43 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-08-04 13:58:41 · 644 阅读 · 0 评论 -
leetcode 刷题之路 78 Binary Tree Postorder Traversal
非递归方式实现二叉树的后序遍历。原创 2014-08-12 14:49:40 · 990 阅读 · 0 评论 -
leetcode 刷题之路 79 Binary Tree Preorder Traversal
非递归实现树的前序遍历原创 2014-08-12 15:01:47 · 815 阅读 · 0 评论 -
leetcode 刷题之路 88 Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2014-08-13 16:36:20 · 745 阅读 · 0 评论