
LeetCode
文章平均质量分 77
solar一抹阳光
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode | Regular Expression Matching(未完成)
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input st原创 2014-07-06 16:52:48 · 878 阅读 · 0 评论 -
LeetCode | First Missing Positive(第一个缺失的正整数)
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant原创 2014-08-10 19:35:52 · 2069 阅读 · 0 评论 -
LeetCode | Edit Distance(字符串编辑距离)
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2014-08-11 21:23:35 · 1001 阅读 · 0 评论 -
LeetCode | Set Matrix Zeroes(矩阵相应行列清零)
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(m原创 2014-08-11 23:47:17 · 955 阅读 · 0 评论 -
LeetCode | 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]原创 2014-08-10 20:24:33 · 979 阅读 · 0 评论 -
LeetCode | 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.题目解析:设置两个指针q,当重复的时候将原创 2014-08-12 16:50:12 · 629 阅读 · 0 评论 -
LeetCode | Gray Code(格雷码)
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 the sequence of原创 2014-08-12 23:19:52 · 1082 阅读 · 0 评论 -
LeetCode | Reverse Linked List II(翻转链表2)
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-13 11:15:03 · 721 阅读 · 0 评论 -
LeetCode | Interleaving String(交叉字符串)
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", ret原创 2014-08-13 20:02:36 · 781 阅读 · 0 评论 -
LeetCode | 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-14 01:21:57 · 645 阅读 · 0 评论 -
LeetCode | 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.题目解析:求树的原创 2014-08-14 12:17:54 · 659 阅读 · 0 评论 -
LeetCode | Convert Sorted Array to Binary Search Tree(有序数组转换成平衡二叉树搜索树)
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.题目解析:gei原创 2014-08-14 14:46:16 · 657 阅读 · 0 评论 -
LeetCode | Word Break II
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "原创 2014-08-20 17:25:23 · 465 阅读 · 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 i原创 2014-08-20 21:58:53 · 499 阅读 · 0 评论 -
LeetCode | Combination Sum II(元素的和---2)
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 combina原创 2014-08-10 17:05:50 · 554 阅读 · 0 评论 -
LeetCode | Search a 2D Matrix(二维矩阵中查找)
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each原创 2014-08-12 00:19:16 · 632 阅读 · 0 评论 -
LeetCode | Balanced Binary Tree(平衡二叉树)
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe原创 2014-08-14 16:35:44 · 768 阅读 · 0 评论 -
LeetCode | Minimum Depth of Binary Tree(树的最短路径)
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.题目解析:原创 2014-08-14 16:52:09 · 877 阅读 · 0 评论 -
LeetCode | Path Sum II(路径和2)
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 = 22, 5 / \原创 2014-08-14 17:38:09 · 561 阅读 · 0 评论 -
LeetCode | Remove Duplicates from Sorted Array II(删除重复的元素2)
Remove Duplicates from Sorted Array II原创 2014-08-12 15:28:21 · 687 阅读 · 0 评论 -
LeetCode | 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-13 10:27:07 · 900 阅读 · 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-08-14 00:37:25 · 617 阅读 · 0 评论 -
LeetCode | 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-14 20:09:43 · 2019 阅读 · 0 评论 -
LeetCode | Combination Sum(元素的和)
#include #include struct Stk{ int arr[20]; int len;};void Print(struct Stk *stack){ for(int i = 0;i len;i++){ printf("%d ",stack->arr[i]); } printf("\n");}//n-数组长原创 2014-08-10 16:34:39 · 830 阅读 · 0 评论 -
LeetCode | Permutation Sequence(找到全排列中的第k个排列)
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""231""3原创 2014-08-11 16:49:16 · 804 阅读 · 0 评论 -
LeetCode | 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, givens = "leetcode",dict = ["leet"原创 2014-08-20 14:10:02 · 386 阅读 · 0 评论 -
LeetCode | Linked List Cycle II
class Solution {public: ListNode *detectCycle(ListNode *head) { if(head == NULL) return head; ListNode *S = head; ListNode *F = head; while(F && F->nex原创 2014-08-20 21:26:17 · 449 阅读 · 0 评论 -
LeetCode | Combinations(n选k全排列)
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]原创 2014-08-12 11:41:08 · 1052 阅读 · 0 评论 -
LeetCode | Remove Duplicates from Sorted List II(删除链表中重复结点2)
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->1-原创 2014-08-12 17:28:21 · 702 阅读 · 0 评论 -
LeetCode | Largest Rectangle in Histogram(直方图围城的最大矩形面积)
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width o原创 2014-08-12 20:05:58 · 1079 阅读 · 0 评论 -
LeetCode | 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-13 21:23:28 · 718 阅读 · 0 评论 -
LeetCode | Distinct Subsequences(不同的子序列)
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non原创 2014-08-14 21:38:23 · 797 阅读 · 0 评论 -
LeetCode | Populating Next Right Pointers in Each Node II(将每一层链接成一个链表)
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant原创 2014-08-15 00:29:07 · 530 阅读 · 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-08-15 00:51:33 · 536 阅读 · 0 评论 -
LeetCode | Triangle(三角形路径和)
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [原创 2014-08-15 10:33:53 · 669 阅读 · 0 评论 -
LeetCode | Longest Consecutive Sequence(最长连续序列)
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3原创 2014-08-15 18:09:04 · 594 阅读 · 0 评论 -
LeetCode | Sum Root to Leaf Numbers(所有根结点到叶节点路径和的和)
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota原创 2014-08-15 19:40:09 · 637 阅读 · 0 评论 -
LeetCode | Palindrome Partitioning II(最少切割次数将一个子串划分成回文子串)
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Return原创 2014-08-16 10:34:51 · 1294 阅读 · 1 评论 -
LeetCode | 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-15 11:18:06 · 613 阅读 · 0 评论 -
LeetCode | Best Time to Buy and Sell Stock II(股票购买抛售问题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-15 11:36:18 · 783 阅读 · 0 评论