
LeetCode
文章平均质量分 64
普通网友
这个作者很懒,什么都没留下…
展开
-
LeetCode 169 Majority Element
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 that the array is non-empty and the majority element原创 2018-01-21 16:36:30 · 192 阅读 · 0 评论 -
LeetCode 496 Next Greater Element I
You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums2. T...原创 2018-02-18 18:31:18 · 194 阅读 · 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 assume no duplicate exis...原创 2018-02-15 11:23:17 · 169 阅读 · 0 评论 -
LeetCode 689 Maximum Sum of 3 Non-Overlapping Subarrays
In a given array nums of positive integers, find three non-overlapping subarrays with maximum sum.Each subarray will be of size k, and we want to maximize the sum of all 3*k entries.Return the result ...原创 2018-02-15 10:24:21 · 335 阅读 · 0 评论 -
LeetCode 287 Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, fi...原创 2018-02-15 09:58:47 · 182 阅读 · 0 评论 -
LeetCode 667 Beautiful Arrangement II
Given two integers n and k, you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requirement: Suppose this list is [a1, a2, a3,原创 2018-01-21 00:05:38 · 214 阅读 · 0 评论 -
LeetCode 718 Maximum Length of Repeated Subarray
Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.Example 1:Input:A: [1,2,3,2,1]B: [3,2,1,4,7]Output: 3Explanation: The repeated sub原创 2018-01-28 23:32:54 · 229 阅读 · 0 评论 -
LeetCode 122 Best Time to Buy and Sell Stock II
这个题和Best Time to Buy and Sell Stock 是有关的。先看下Best Time to Buy and Sell Stock II:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitt原创 2018-01-23 14:56:35 · 153 阅读 · 0 评论 -
LeetCode 532 K-diff Pairs in an Array
Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers in原创 2018-01-23 14:38:58 · 196 阅读 · 0 评论 -
LeetCode 401 Binary Watch
A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED represents a zero or one, with the least significant bit o原创 2017-07-01 12:15:09 · 273 阅读 · 0 评论 -
LeetCode 23 Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.合并k个有序链表。最直接的想法先合并两条链表,然后再与第三条链表进行合并,那么时间复杂度是o(2n+3n……kn)=o(nk²)另一种想法是借鉴归并排序的思想,两两合并。T(n)=2T(n原创 2017-07-01 12:19:05 · 213 阅读 · 0 评论 -
LeetCode 201 Bitwise AND of Numbers Range
Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.这个题开始想了想,以为直接loop就行了,但是又一想好歹是个中等难度,有这么简单?管他呢就简单loop。果然==Time Limit Exceeded。那有什么骚操作呢?就参考了别人的解法。有这么一个思路。说结果原创 2017-07-02 10:17:22 · 205 阅读 · 0 评论 -
LeetCode 541 Reverse String II
Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of th原创 2018-01-14 17:08:10 · 224 阅读 · 0 评论 -
LeetCode 448 Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.原创 2017-12-23 22:45:14 · 153 阅读 · 0 评论 -
LeetCode 698 Partition to K Equal Sum Subsets
Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.Example 1:Input: nums = [4, 3, 2, 3, 5,...原创 2018-08-21 00:09:51 · 203 阅读 · 0 评论