leetcode
文章平均质量分 60
暴躁的猴子
比你优秀的人比你更努力!
展开
-
leetcode 56. Merge Intervals
题目描述:Given a collection of intervals, merge all overlapping intervals.若给定的两个区间有重叠,则将这两个区间合并(相当于有重叠的区间求并集)Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanati...原创 2019-05-18 23:31:07 · 192 阅读 · 0 评论 -
leetcode 518. Coin Change 2找零钱的方案数-动态规划
题目描述:链接:https://www.nowcoder.com/questionTerminal/185dc37412de446bbfff6bd21e4356ec来源:牛客网有一个数组changes,changes中所有的值都为正数且不重复。每个值代表一种面值的货币,每种面值的货币可以使用任意张,对于一个给定值x,请设计一个高效算法,计算组成这个值的方案数。给定一个int数组c...原创 2019-06-09 12:48:51 · 1576 阅读 · 0 评论 -
leetcode 224. Basic Calculator
题目描述Implement a basic calculator to evaluate a simple expression string.The expression string may contain open(and closing parentheses), the plus+or minus sign-,non-negativeintegers and em...原创 2019-06-26 19:46:49 · 134 阅读 · 0 评论 -
leetcode 227. Basic Calculator II
题目描述Implement a basic calculator to evaluate a simple expression string.The expression string contains onlynon-negativeintegers,+,-,*,/operators and empty spaces. The integer division shou...原创 2019-06-26 21:07:56 · 194 阅读 · 0 评论 -
leetcode 3. Longest Substring Without Repeating Characters
题目描述:Given a string, find the length of thelongest substringwithout repeating characters.Example 1:Input: "abcabcbb"Output: 3 Explanation: The answer is "abc", with the length of 3. Examp...原创 2019-07-03 00:46:39 · 111 阅读 · 0 评论 -
leetcode 66. Plus One
题目描述:Given anon-emptyarray of digitsrepresenting a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each ...原创 2019-07-03 10:57:33 · 101 阅读 · 0 评论 -
leetcode 347. Top K Frequent Elements
题目描述Given a non-empty array of integers, return thekmost frequent elements.Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]Example 2:Input: nums = [1], k = 1Output: [1]Note...原创 2019-06-24 23:43:59 · 115 阅读 · 0 评论 -
二叉树路径和系列-leetcode 129. Sum Root to Leaf Numbers
题目描述:Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find t...原创 2019-07-03 21:16:48 · 137 阅读 · 0 评论 -
二叉树路径和系列-leetcode 112. Path Sum
题目描述:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Note:A leaf is a node with no children.E...原创 2019-07-06 11:59:44 · 196 阅读 · 0 评论 -
leetcode 692. Top K Frequent Words
题目描述Given a non-empty list of words, return thekmost frequent elements.Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with ...原创 2019-06-25 20:26:05 · 143 阅读 · 0 评论 -
leetcode 12. Integer to Roman
题目描述Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-06-20 12:22:56 · 105 阅读 · 0 评论 -
leetcode 322. Coin Change 贪心+动态规划
题目描述:You are given coins of different denominations and a total amount of moneyamount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of...原创 2019-06-09 20:28:09 · 731 阅读 · 0 评论 -
leetcode 58. Length of Last Word
题目描述:Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word does not exist, return 0.Note:A word i...原创 2019-05-19 00:19:49 · 124 阅读 · 0 评论 -
leetcode 3. Longest Substring Without Repeating Characters(最长不重复字串)
题目描述:Given a string, find the length of thelongest substringwithout repeating characters.Example 1:Input: "abcabcbb"Output: 3 Explanation: The answer is "abc", with the length of 3. Exam...原创 2019-05-20 12:06:01 · 411 阅读 · 0 评论 -
leetcode 47. Permutations II
题目描述:Given a collection of numbers that might contain duplicates, return all possible unique permutations.Example:Input: [1,1,2]Output:[ [1,1,2], [1,2,1], [2,1,1]]思路1:递归基本思路和46题一样,...原创 2019-05-13 00:18:19 · 114 阅读 · 0 评论 -
leetcode 49. Group Anagrams
题目描述:Given an array of strings, group anagrams together.Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat","tan"], ["bat"]]Note:All inpu...原创 2019-05-13 16:21:07 · 104 阅读 · 0 评论 -
leetcode 349. Intersection of Two Arrays
题目描述:Given two arrays, write a function to compute their intersection.Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2]Example 2:Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]Ou...原创 2019-06-18 19:53:56 · 197 阅读 · 0 评论 -
leetcode 986. Interval List Intersections
题目描述Given two listsofclosedintervals, each list of intervals is pairwise disjoint and in sorted order.Return the intersection of these two interval lists.(Formally, a closed interval[a, b](...原创 2019-06-18 20:59:39 · 241 阅读 · 0 评论 -
leetcode 57. Insert Interval
题目描述:Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times....原创 2019-06-19 01:08:30 · 193 阅读 · 0 评论 -
二叉树路径和系列-(LeetCode 113. Path Sum II)剑指offer:二叉树中和为某一值的路径
题目描述输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。(注意: 在返回值的list中,数组长度大的数组靠前)给出一个二叉树: 接下来列表了解上面二叉树的遍历过...原创 2018-11-09 23:57:56 · 182 阅读 · 0 评论 -
二叉树路径和系列-257. Binary Tree Paths
题目描述Given a binary tree, return all root-to-leaf paths.Note:A leaf is a node with no children.Example:Input: 1 / \2 3 \ 5Output: ["1->2->5", "1->3"]Explanation: A...原创 2019-07-06 18:28:26 · 148 阅读 · 0 评论 -
(0-1背包问题)leetcode 416. Partition Equal Subset Sum
题目描述:Given anon-emptyarray containingonly positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note:Each of the arra...原创 2019-07-17 14:49:36 · 133 阅读 · 0 评论 -
leetcode 125. Valid Palindrome
题目描述:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note:For the purpose of this problem, we define empty string as valid palindrome....原创 2019-08-08 17:43:40 · 137 阅读 · 0 评论 -
leetcode 98. Validate Binary Search Tree
题目描述:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keysless thanthe node's key...原创 2019-08-18 20:59:42 · 123 阅读 · 0 评论 -
leetcode 173. Binary Search Tree Iterator
题目描述:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Callingnext()will return the next smallest number in the BST.Exampl...原创 2019-08-18 22:05:32 · 159 阅读 · 0 评论 -
leetcode 153. Find Minimum 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]).Find the minimum element.You may assum...原创 2019-08-19 11:45:12 · 151 阅读 · 0 评论 -
DP系列-leetcode 673. Number of Longest Increasing Subsequence
题目描述:Given an unsorted array of integers, find the number of longest increasing subsequence.Example 1:Input: [1,3,5,4,7]Output: 2Explanation: The two longest increasing subsequence are [1, 3,...原创 2019-08-07 20:27:52 · 138 阅读 · 0 评论 -
leetcode 48. Rotate Image
题目描述:You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the imagein-place, which means you have to modify the input 2D m...原创 2019-08-19 18:03:41 · 117 阅读 · 0 评论 -
leetcode 42. Trapping Rain Water
题目描述:Givennnon-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.The above elevation map is represented b...原创 2019-08-25 15:58:25 · 147 阅读 · 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.Note:A leaf is a node with no ...原创 2019-08-16 22:01:37 · 162 阅读 · 0 评论 -
链表与快慢指针
之前刷剑指offer遇到寻找链表环的入口节点,需要使用到快慢指针,然后题一变,发现自己总是不能立马联想起来。总结一下快慢指针法在链表中的一些常见的用处。一、快慢指针判断单链表是否有环leetcode 141https://leetcode.com/problems/linked-list-cycle/submissions/快指针每次走2步,慢指针每次走1步,如果链表中有环,则两个指...原创 2019-08-01 23:06:29 · 218 阅读 · 0 评论 -
leetcode 124. Binary Tree Maximum Path Sum(递归)
题目描述:Given anon-emptybinary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child co...原创 2019-07-22 18:47:07 · 210 阅读 · 0 评论 -
leetcode 128. Longest Consecutive Sequence-Hashset
题目描述:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.Your algorithm should run in O(n) complexity.Example:Input:[100, 4, 200, 1, 3, 2]Outpu...原创 2019-07-22 12:23:53 · 117 阅读 · 0 评论 -
LeetCode 698. Partition to K Equal Sum Subsets
题目描述:Given an array of integersnumsand a positive integerk, find whether it's possible to divide this array intoknon-empty subsets whose sums are all equal.Example 1:Input: nums = [4, 3, 2...原创 2019-07-17 20:05:24 · 132 阅读 · 0 评论 -
leetcode 45. Jump Game II(贪心)
题目描述: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.Your goa...原创 2019-07-21 00:03:16 · 237 阅读 · 0 评论 -
面试题-利用栈寻找下一个较大元素
题目描述:给出一个数组,向右寻找每一个元素的下一个较大的元素,没有更大的则为-1举例{4,6,1,3,2,5}则求得的答案应为{6,-1,3,5,5,-1}思路:参考:https://www.cnblogs.com/linkstar/p/6180816.html不能暴力破解,且需要用o(n)的方法来实现。本题需要用到栈来解决。我们声明一个数组,用来存放每个元素对...原创 2019-07-21 11:37:25 · 355 阅读 · 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.Determin...原创 2019-07-21 15:41:41 · 131 阅读 · 0 评论 -
leetcode 4. Median of Two Sorted Arrays(二分查找)
题目描述:There are two sorted arraysnums1andnums2of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).You may assumenums...原创 2019-07-25 17:26:59 · 219 阅读 · 0 评论 -
leetcode 496. Next Greater Element I(栈)
题目描述:You are given two arrays(without duplicates)nums1andnums2wherenums1’s elements are subset ofnums2. Find all the next greater numbers fornums1's elements in the corresponding places ofn...原创 2019-07-21 18:24:47 · 190 阅读 · 0 评论 -
leetcode【39,40,77,78,90,216】排列组合问题
组合问题:题目中涉及到all possible sulutions时就要用到搜索算法,用深度优先搜索来解决。leetcode 78.Subsets题目描述Given a set ofdistinctintegers,nums, return all possible subsets (the power set).Note:The solution set must ...原创 2019-08-03 00:37:48 · 362 阅读 · 0 评论