- 博客(50)
- 收藏
- 关注
原创 [leetcode 241] Different Ways to Add Parentheses--------计算运算公式字符串中所有可能结果
Question:Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are+, - and *.
2016-03-30 23:26:42 518
原创 [leetcode 173] Binary Search Tree Iterator-------为二叉搜索树实现迭代器功能
Question:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.
2016-03-30 22:23:28 914
原创 C++ STL 中lower_bound() 和 upper_bound()讲解
1、lower_bound()在有序的范围内(具有大于或等于指定值的值)查找第一个元素的位置,该排序标准可由二进制谓词指定。 语法: template ForwardIterator lower_bound( ForwardIterator first, ForwardIterator last, const Type& valu
2016-03-29 23:24:57 13180
原创 [leetcode 300] Longest Increasing Subsequence
Question:Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3
2016-03-29 23:13:27 527
原创 [leetcode 11] Container With Most Water
Question:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai)
2016-03-29 22:20:22 548
原创 [leetcode 48] Rotate Image--------矩阵旋转90度
Quesiton: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?分析:将一个n*n 的矩阵旋转90度,原地旋转,O(1)的空间复
2016-03-23 23:40:26 1106
原创 [leetcode ] Factor Combinations -------------因数组合
Question:Numbers can be regarded as product of its factors. For example,8 = 2 x 2 x 2; = 2 x 4.Write a function that takes an integer n and return all possible combinations of its factors.
2016-03-23 23:07:41 802
原创 [leetcode 75] Sort Colors-----------只有三种颜色的排序
Question: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 us
2016-03-23 22:43:07 900
原创 [leetcode 59] Spiral Matrix II--------数组转圈赋值
Question: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 following matrix:[ [ 1, 2, 3 ],
2016-03-23 22:05:34 833
原创 [leetcode 64] Minimum Path Sum------从左上角到右下角的最小路径值
Question:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either d
2016-03-23 08:26:40 2871
原创 [leetcode 24]Swap Nodes in Pairs-----成对翻转链表中的节点
Question: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 co
2016-03-22 21:58:46 376
原创 [leetcode 216] Combination Sum III ------组合数的和(回溯法)
Question:Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure
2016-03-22 21:30:13 599
原创 [leetcode 277]Find the Celebrity---------找名人
Question:Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a celebrity is that all the other n - 1 people know
2016-03-18 23:02:04 955
原创 [leetcode 244] Shortest Word Distance II------------字典中两个字符串的最短距离
Question:This is a follow up of Shortest Word Distance. The only difference is now you are given the list of words and your method will be called repeatedly many times with different parameter
2016-03-18 22:32:29 787
原创 [leetcode 46] Permutations------数组中元素的所有排列组合集合
Question:Given a collection of distinct 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], [3,1,2], and [
2016-03-16 23:10:50 541
原创 [leetcode 285] Inorder Successor in BST---查找二叉搜索树中某个节点在中序遍历中的后续节点
Question:Given a binary search tree and a node in it, find the in-order successor of that node in the BST.Note: If the given node has no in-order successor in the tree, return null.分析:
2016-03-16 21:54:43 1565
原创 [leetcode 141] Linked List Cycle----判断链表是否为循环链表
Question:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?分析:判断一个链表是否为循环链表,只要有NULL出现就不是循环链表。方法:设置两个指针,第一个指针从头开始走两步每次,第二个指针每
2016-03-15 22:42:23 727
原创 [leetcode 1] Two Sum
Question:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:
2016-03-15 22:25:43 276
原创 [leetcode 328] Odd Even Linked List
Question:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should
2016-03-15 21:32:24 464
原创 [leetcode 121] Best Time to Buy and Sell Stock---只能买卖股票一次的最大收益
Question: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 o
2016-03-15 08:26:45 1162
原创 [leetcode 89] Gray Code---实现格雷码
Question:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print t
2016-03-14 22:56:30 449
原创 [leetcode 153]Find Minimum in Rotated Sorted Array----求旋转数组的最小值
Question: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).Find the minimum element.You may assume no dupli
2016-03-14 22:31:32 544
原创 [leetcode 62]Unique Paths---机器人向左或向下走到右下角的路径数目
Question:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is tryin
2016-03-14 21:49:11 1239
原创 [leetcode 250]Count Univalue Subtrees ------元素都相同的子树个数
Question:Given a binary tree, count the number of uni-value subtrees.A Uni-value subtree means all nodes of the subtree have the same value.For example:Given binary tree, 5
2016-03-12 17:02:36 3247
原创 [leetcode 298] Binary Tree Longest Consecutive Sequence---求二叉树连续序列的长度
Question:Given a binary tree, find the length of the longest consecutive sequence path.The path refers to any sequence of nodes from some starting node to any node in the tree along the pare
2016-03-12 16:01:28 702
原创 [leetcode 22]Generate Parentheses-----n对括号可以组成的括号对序列
Question:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()",
2016-03-11 23:25:39 939
原创 [leetcode 309]Best Time to Buy and Sell Stock with Cooldown--买卖股票with冷却期(DP法)
Question: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 l
2016-03-10 23:02:33 2615
原创 [leetcode 53] Maximum Subarray----最大子数组的和
Question: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,1,−5,4],the contiguous subarra
2016-03-10 13:05:35 793
原创 [leetcode 286] Walls and Gates---各个点到门的距离
Question:You are given a m x n 2D grid initialized with these three possible values.-1 - A wall or an obstacle.0 - A gate.INF - Infinity means an empty room. We use the value 231 - 1 = 21474
2016-03-09 23:45:42 542
原创 [leetcode 116] Populating Next Right Pointers in Each Node---层序遍历标记每一层的末尾
Question:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its ne
2016-03-09 23:09:12 415
原创 [leetcode 230]Kth Smallest Element in a BST----求二叉搜索树的第K小值
Question:Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.分析:题目是
2016-03-09 21:51:39 570
原创 [leetcode 255] Verify Preorder Sequence in Binary Search Tree ---先序遍历验证二叉搜索树
Question:Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary search tree.You may assume each number in the sequence is unique.Follow up: C
2016-03-08 23:07:29 1434
原创 [leetcode 108] Convert Sorted Array to Binary Search Tree
Question:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.分析:题目意思是根据给定的一个有序数组,创建一个二叉平衡树。因为数组是从小到大有序的,所以很简单,将数组的中间数作为根节点,这样左右两边的高度差小于等于1,递归操作
2016-03-08 22:02:39 338
原创 [leetcode 35]Search Insert Position
Question: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 duplicate
2016-03-07 23:35:00 277
原创 [leetcode 96]Unique Binary Search Trees--二叉搜索树的个数问题。
Question: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
2016-03-07 23:25:10 316
原创 [leetcode 137] Single Number II
Question:Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement
2016-03-07 22:25:02 331
原创 [leetcode 156]Binary Tree Upside Down
Question:Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree w
2016-03-07 21:46:58 490
原创 [leetcode 12] Integer to Roman
Question:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.分析:此问题首先要了解罗马数字规则(详见C++分类中的文章《罗马数字转换成阿拉伯数字》,连接在文章下方)根据规则可以知道,当4,5,9
2016-03-05 16:11:15 306
原创 [leetcode 259]3Sum Smaller
Question:Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 that satisfy the condition nums[i] + nums[j] + nums[k] .For example, given nums =
2016-03-04 22:49:17 1343
原创 [leetcode 318]Maximum Product of Word Lengths--判断两个字符串是否有相同的字符
Question:Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain onl
2016-03-04 22:24:40 541
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人