
算法
文章平均质量分 65
LawFile
这个作者很懒,什么都没留下…
展开
-
#1477. Find Two Non-overlapping Sub-arrays Each With Target Sum
题目描述:Given an array of integersarrand an integertarget.You have to findtwo non-overlapping sub-arraysofarreach with sum equaltarget. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays ...原创 2020-07-27 11:46:51 · 363 阅读 · 0 评论 -
#1423. Maximum Points You Can Obtain from Cards
题目描述:There are several cardsarranged in a row, and each card has an associated number of pointsThe points are given in the integer arraycardPoints.In one step, you can take one card from the beginning or from the end of the row. You have to take exa...原创 2020-07-27 11:45:36 · 283 阅读 · 0 评论 -
#752. Open the Lock
题目描述:You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots:'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap around: for example we can turn'9'to be'0', or'0'to be'9'. Each move consi...原创 2020-07-27 11:44:24 · 304 阅读 · 0 评论 -
#1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
题目描述:Given anarray of integersnumsand anintegerlimit, return the size of the longestnon-emptysubarray such that the absolute difference between any two elements of this subarray is less than or equal tolimit.Example 1:Input: nums = [8,2,4,7]...原创 2020-07-27 11:42:50 · 248 阅读 · 0 评论 -
#946. Validate Stack Sequences
题目描述:Given two sequencespushedandpoppedwith distinct values,returntrueif and only if this could have been the result of a sequence of push and pop operations on an initially empty stack.Example 1:Input: pushed = [1,2,3,4,5], popped = [4,5,3,2...原创 2020-07-27 11:41:27 · 158 阅读 · 0 评论 -
LeetCode #114 - 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原创 2017-10-01 17:01:40 · 231 阅读 · 0 评论 -
LeetCode #84 - 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原创 2017-09-30 20:26:05 · 221 阅读 · 0 评论 -
LeetCode #79 - Word Search
题目描述:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or原创 2017-09-30 20:21:07 · 229 阅读 · 0 评论 -
LeetCode #78 - Subsets
题目描述:Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[原创 2017-09-30 20:10:02 · 214 阅读 · 0 评论 -
LeetCode #75 - 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原创 2017-09-30 15:06:16 · 210 阅读 · 0 评论 -
LeetCode #27 - Remove Element
题目描述:Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant原创 2017-09-22 10:56:33 · 204 阅读 · 0 评论 -
LeetCode #72 - 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原创 2017-09-30 14:46:35 · 232 阅读 · 0 评论 -
LeetCode #85 - Maximal Rectangle
题目描述:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1原创 2017-09-30 20:37:45 · 246 阅读 · 0 评论 -
LeetCode #104 - 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.这种题型显然应该采用递归的方法,从任意一个节点开始原创 2017-09-30 20:50:10 · 205 阅读 · 0 评论 -
LeetCode #28 - Implement strStr()
题目描述:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.这道题为easy难度,所以对时间复杂度要求不高,可以直接用暴力的方法解决,即先在haystack中匹配needle的第原创 2017-09-22 11:16:42 · 188 阅读 · 0 评论 -
LeetCode #105 - 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.根据前序遍历和中序遍历构造二叉树。还是利用递归来解决,前序遍历的第一个元素即为二叉树的根节点原创 2017-10-01 16:55:34 · 295 阅读 · 0 评论 -
LeetCode #56 - 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].要将区间合并,即找出相交的区间范围,然后合并。思想方法就是遍历区间数组,并查找已经原创 2017-09-30 13:08:45 · 209 阅读 · 0 评论 -
LeetCode #76 - Minimum Window Substring
题目描述:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum win原创 2017-09-30 16:00:06 · 246 阅读 · 0 评论 -
LeetCode #91 - Decode Ways
题目描述:A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the tot原创 2016-11-02 09:19:18 · 328 阅读 · 0 评论 -
LeetCode #1030. Matrix Cells in Distance Order
题目描述:We are given a matrix withRrows andCcolumns has cells with integer coordinates(r, c), where0 <= r < Rand0 <= c < C.Additionally, we are given a cell in that matrix with co...原创 2019-08-31 12:06:13 · 134 阅读 · 0 评论 -
LeetCode #55 - 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.原创 2017-09-30 12:37:58 · 211 阅读 · 0 评论 -
LeetCode #53 - Maximum Subarray
题目描述: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 subarray [4原创 2017-09-30 12:18:04 · 213 阅读 · 0 评论 -
LeetCode #21 - 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.此题可以直接模拟归并排序的步骤,但是要小心指针为空的情况。/** * Defini原创 2017-09-18 17:47:14 · 449 阅读 · 0 评论 -
LeetCode #18 - 4Sum
题目描述:Given an array S of n integers, are there elements a,b, c, and d in S such that a + b +c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The s原创 2016-10-19 16:19:02 · 276 阅读 · 0 评论 -
LeetCode #22 - 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:[ "((()))", "(()())", "(())()",原创 2017-09-18 21:16:37 · 538 阅读 · 0 评论 -
LeetCode #19 - Remove Nth Node From End of List
题目描述: Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second n...原创 2017-09-18 16:51:03 · 474 阅读 · 0 评论 -
LeetCode #15 - 3Sum
题目描述:Given an array S of n integers, are there elements a,b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not c原创 2016-09-28 22:19:43 · 254 阅读 · 0 评论 -
LeetCode #32 - Longest Valid Parentheses
题目描述:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring原创 2017-09-25 23:56:22 · 274 阅读 · 0 评论 -
LeetCode #13 - Roman to Integer
题目描述:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.本题较简单,我采用的方法是从字符串第一位开始进行识别并确定其代表的数值大小后加入integer,根据罗马数字表示规则,进行分类讨论,识别完后将字符删去。c原创 2016-09-22 22:33:07 · 329 阅读 · 0 评论 -
LeetCode #10 - 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 enti原创 2017-09-17 10:14:42 · 251 阅读 · 0 评论 -
LeetCode #23 - Merge k Sorted Lists
题目描述:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity这道题可以利用mergeTwoLists来做,一种方法是将k个链表一个一个地归并,即需要k步。随着归并的次数越多,已经归并的链表会越来越长,所以效率比较差。在这道题的最后一个测试案例中原创 2017-09-19 13:44:34 · 360 阅读 · 0 评论 -
LeetCode #24 - 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 consta原创 2017-09-19 14:43:54 · 330 阅读 · 0 评论 -
LeetCode #49 - Group Anagrams
题目描述:Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]找出字原创 2017-09-30 12:14:17 · 233 阅读 · 0 评论 -
LeetCode #46 - Permutations
题目描述: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原创 2017-09-30 11:59:58 · 224 阅读 · 0 评论 -
LeetCode #42 - 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原创 2017-09-30 11:49:41 · 247 阅读 · 0 评论 -
LeetCode #39 - Combination Sum
题目描述:Given a set of candidate numbers (C) (without duplicates) 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 f...原创 2017-09-30 11:27:44 · 256 阅读 · 0 评论 -
LeetCode #33 - Search in Rotated Sorted Array
题目描述:Suppose an array sorted in ascending order 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 sear原创 2017-09-30 11:08:10 · 312 阅读 · 0 评论 -
LeetCode #26 - 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原创 2017-09-21 20:06:53 · 209 阅读 · 0 评论 -
LeetCode #25 - Reverse Nodes in k-Group
题目描述:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If t原创 2017-09-21 19:58:21 · 377 阅读 · 0 评论 -
LeetCode #206 - 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?实现链表的翻转,而且题目提示可以尝试迭代和递归两种方原创 2017-09-20 11:11:44 · 324 阅读 · 0 评论