![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LC重点
文章平均质量分 57
Ellie_
这个作者很懒,什么都没留下…
展开
-
[LeetCode]646. Maximum Length of Pair Chain<DP>
You are given n pairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair (c, d) can follow another pair (a, b) if and only if b . Chain转载 2017-07-31 16:04:53 · 554 阅读 · 0 评论 -
[LeetCode]349. Intersection of Two Arrays
Binary Search很简单的一道题,但是犯了好多错误。要求:再从头写一遍,要求一次bug-free AC.https://leetcode.com/problems/intersection-of-two-arrays/description/Given two arrays, write a function to compute their interse原创 2017-08-03 16:50:28 · 346 阅读 · 0 评论 -
[LeetCode]141. Linked List Cycle
Two pointers + Linked list题目。很容易想到的方法是用hashSet来进行存储。而要用到O(1)的空间的话,则需要两个指针,一快一慢,若有circle,终会相遇。The fast runner will eventually meet the slow runner. Why? Consider this case (we name it case A) - The f原创 2017-08-11 10:53:43 · 286 阅读 · 0 评论 -
[LeetCode]374. Guess Number Higher or Lower<Binary Search>
注意亮点。1、low=mid+1; high=mid;2、mid=(high-low)/2+low; 不可以用mid=(low+high)/2,因为加了以后数据有可能会溢出。We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to gu原创 2017-08-03 16:03:53 · 274 阅读 · 0 评论 -
[LeetCode]160. Intersection of Two Linked Lists
重点在于两个list的长度。如何可以巧妙地使得两个不同长度的list的指针遍历到同一个位置上去。Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A:原创 2017-08-11 15:13:31 · 309 阅读 · 0 评论 -
[LeetCode]594. Longest Harmonious Subsequence<HashMap>
We define a harmonious array is an array where the difference between its maximum value and its minimum value is exactly 1.Now, given an integer array, you need to find the length of its longest h原创 2017-08-04 16:37:22 · 269 阅读 · 0 评论 -
[LeetCode]110. 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原创 2017-07-27 17:43:10 · 259 阅读 · 0 评论 -
[LeetCode]303. Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRange转载 2017-07-28 20:49:32 · 253 阅读 · 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,-1,2,1] ha原创 2017-07-29 08:26:37 · 184 阅读 · 0 评论 -
[LeetCode]257. Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]/**原创 2017-07-26 10:54:15 · 212 阅读 · 0 评论 -
[LeetCode]442. Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it without ex原创 2017-04-25 20:05:25 · 211 阅读 · 0 评论 -
[LeetCode]406. Queue Reconstruction by Height
Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of t转载 2017-07-25 19:11:27 · 211 阅读 · 0 评论 -
[LeetCode]538. Convert BST to Greater Tree
Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.Exam原创 2017-08-07 16:29:34 · 241 阅读 · 0 评论 -
[leetCode]565. Array Nesting
A zero-indexed array A consisting of N different integers is given. The array contains all integers in the range [0, N - 1].Sets S[K] for 0 S[K] = { A[K], A[A[K]], A[A[A[K]]], ... }.Sets S原创 2017-08-01 09:26:48 · 225 阅读 · 0 评论 -
[LeetCode]404. Sum of Left Leaves 树的典型题目
Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.转载 2017-08-07 22:07:59 · 225 阅读 · 0 评论 -
[LeetCode]238. Product of Array Except Self
Array类型的Medium题目。计算数组里除了自己的元素的乘积。不允许用到除法。我们想,对于某一个数字,如果我们知道其前面所有数字的乘积,同时也知道后面所有的数乘积,那么二者相乘就是我们要的结果。不需要用到两个数组来存放结果,用一个常数来存放一边的值。Given an array of n integers where n > 1, nums, return an arr原创 2017-08-01 16:11:50 · 246 阅读 · 0 评论 -
[LeetCode]167. Two Sum II - Input array is sorted
Two Sum的变种。增加了新的条件,给出的数组元素是按照增序排列的。在新条件下不需要再用到HashMap,一定要利用好“sorted in ascending order”这个新特性。思路:Two Pointers + Binary Search。从首尾开始逼近我们想要的值……同时注意需要存放的下标的值。Given an array of integers that is a原创 2017-08-01 16:27:40 · 226 阅读 · 0 评论 -
[LeetCode]122. Best Time to Buy and Sell Stock II
Greedy+Array. Easy mode.我的解法太啰嗦了,标准答案才是真正用到了“greedy”的精髓。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.原创 2017-08-01 17:11:54 · 340 阅读 · 0 评论 -
[LeetCode]169. Majority Element
Array. Divide and Conquer. Bit manipulation.Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume tha原创 2017-08-01 17:37:00 · 215 阅读 · 0 评论 -
[LeetCode]459. Repeated Substring Pattern
Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase Engli原创 2017-08-08 16:56:09 · 227 阅读 · 0 评论 -
[LeetCode]Sliding Window Algorithm相关题目总结【重要】
滑动窗口算法的一些具体应用。subString的问题。https://leetcode.com/problems/find-all-anagrams-in-a-string/discuss/原创 2017-08-06 17:10:04 · 3539 阅读 · 1 评论