![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 73
vincent-xia
这个作者很懒,什么都没留下…
展开
-
LeetCode63:Unique Paths II
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 is marked as 1 and 0 respectively in the原创 2015-06-12 16:05:00 · 1203 阅读 · 0 评论 -
LeetCode121: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),原创 2015-06-15 10:47:40 · 657 阅读 · 0 评论 -
LeetCode236:Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two node原创 2015-07-27 15:57:21 · 613 阅读 · 0 评论 -
LeetCode189:Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note: Try to come up as many solutions as you can, ther原创 2015-07-06 11:39:15 · 1348 阅读 · 0 评论 -
LeetCode78:Subsets
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 not contain duplicate subsets. For example, If原创 2015-07-06 17:33:29 · 5213 阅读 · 2 评论 -
LeetCode39:Combination Sum
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 repeated number may be chosen from C unlimited number of t原创 2015-07-06 20:58:02 · 4446 阅读 · 2 评论 -
LeetCode216:Combination Sum III
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 that numbers w原创 2015-07-06 21:36:01 · 1068 阅读 · 0 评论 -
LeetCode145:Binary Tree Postorder Traversal
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 solution is trivial, could you do it iteratively?二叉原创 2015-07-14 11:21:42 · 686 阅读 · 0 评论 -
LeetCode94:Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, return [1,3,2].Note: Recursive solution is trivial, could you do it iteratively?二叉树的原创 2015-07-14 09:56:27 · 682 阅读 · 0 评论 -
LeetCode123: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原创 2015-06-16 09:54:29 · 3220 阅读 · 0 评论 -
LeetCode211:Add and Search Word - Data structure design
Design a data structure that supports the following two operations:void addWord(word) bool search(word) search(word) can search a literal word or a regular expression string containing only letters a原创 2015-07-06 20:13:51 · 1257 阅读 · 0 评论 -
LeetCode234:Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?给定一个单链表,判断它的元素是否是回文。要求在O(n)的时间复杂度和O(1)的空间复杂度内求解。如果没有时间复杂度的限制,可以直接将链表反转再比较就原创 2015-07-27 15:47:28 · 930 阅读 · 0 评论 -
LeetCode3:Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For “原创 2015-07-13 00:24:28 · 1022 阅读 · 0 评论 -
LeetCode62:Unique Paths
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 trying to reach the原创 2015-06-12 11:33:21 · 805 阅读 · 0 评论 -
LeetCode192:House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house原创 2015-06-13 09:20:18 · 800 阅读 · 0 评论 -
LeetCode139:Word Break
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 example, given s = “leetcode”, dict = [“leet”, “co原创 2015-07-02 00:35:47 · 2645 阅读 · 0 评论 -
LeetCode225:Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get the top element. empty() – Return whether原创 2015-07-10 22:46:38 · 1439 阅读 · 0 评论 -
LeetCode155:Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack.pop() – Removes the element on top of the stack.top() – Get the t原创 2015-07-10 23:32:51 · 802 阅读 · 0 评论 -
LeetCode20:Valid Parentheses
Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. The brackets must close in the correct order, “()” and “()[]{}” are all valid原创 2015-07-11 00:02:15 · 933 阅读 · 0 评论 -
LeetCode213:House Robber II
Note: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time原创 2015-06-13 11:14:36 · 2397 阅读 · 0 评论 -
LeetCode208:Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.Note: You may assume that all inputs are consist of lowercase letters a-z.Hide Tags Data Structure Trie实现一棵Trie树以及实现查询的功能,根据上一篇文章中的分析和伪代码可以原创 2015-07-03 15:44:12 · 1245 阅读 · 0 评论 -
LeetCode232:Implement Queue using Stacks
Implement the following operations of a queue using stacks.push(x) – Push element x to the back of queue.pop() – Removes the element from in front of queue.peek() – Get the front element.empty() –原创 2015-07-10 23:08:22 · 1156 阅读 · 0 评论 -
LeetCode70:Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?设到第i台阶有A[i]那么到第1台阶有A[1]=原创 2015-06-14 23:12:43 · 851 阅读 · 0 评论 -
LeetCode26: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 cons原创 2015-07-06 15:51:00 · 551 阅读 · 0 评论 -
LeetCode40:Combination Sum II
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 number in C may only be used once in the combinat原创 2015-07-06 21:17:58 · 1535 阅读 · 0 评论 -
LeetCode11:Container With Most Water
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) and (i, 0). Fin原创 2015-07-20 16:46:46 · 1352 阅读 · 0 评论 -
LeetCode42:Trapping Rain Water
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.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]原创 2015-07-20 16:22:02 · 707 阅读 · 0 评论 -
LeetCode227:Basic Calculator II
Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should trunca原创 2015-07-20 16:48:00 · 946 阅读 · 0 评论 -
LeetCode238:Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements ofnums except nums[i].Solve it without division and in O(原创 2015-07-20 15:56:13 · 1218 阅读 · 0 评论 -
LeetCode104: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.Show TagsShow Similar Proble原创 2015-08-13 23:25:13 · 698 阅读 · 0 评论 -
LeetCode146: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原创 2015-08-02 10:05:04 · 1820 阅读 · 0 评论 -
LeetCode218:The Skyline Problem
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as原创 2015-08-04 11:09:06 · 3659 阅读 · 0 评论 -
LeetCode237:Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with val原创 2015-07-24 15:22:47 · 726 阅读 · 0 评论 -
LeetCode203:Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5Credits:Special thanks原创 2015-07-24 15:46:17 · 1835 阅读 · 0 评论 -
LeetCode235:Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw原创 2015-07-24 16:18:04 · 663 阅读 · 0 评论 -
LeetCode222:Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely fille原创 2015-07-29 17:17:00 · 1445 阅读 · 0 评论 -
LeetCode206:Reverse Linked List
Reverse a singly linked list.click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?使用迭代和递归实现单链表的反转。迭代的方法之间在剑指offer上面原创 2015-07-30 11:22:27 · 2116 阅读 · 0 评论 -
LeetCode22:Generate Parentheses
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: “((()))”, “(()())”, “(())()”, “()(())”, “(原创 2015-07-07 11:27:50 · 1564 阅读 · 0 评论 -
LeetCode131:Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = “aab”, Return [原创 2015-07-07 17:51:57 · 2339 阅读 · 0 评论 -
LeetCode49:Anagrams
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in lower-case.这道题是题目都没读懂,不知道Anagrams什么意思。Anagrams的意思是那些字符串的组成字符相同。比如说abc,那么abc这三个字符的所有排列都是Anagr原创 2015-07-14 09:10:45 · 706 阅读 · 0 评论