二分答案
文章平均质量分 86
flyatcmu
这个作者很懒,什么都没留下…
展开
-
Magnetic Force Between Two Balls
In universe EarthC-137, Rick discovered a special form of magnetic force betweentwo balls if they are put in his new invented basket. Rick hasnempty baskets, theithbasket is atposition[i], Morty hasmballs and needs to distribute the balls into the...原创 2020-08-16 14:00:31 · 255 阅读 · 0 评论 -
Minimum Number of Days to Make m Bouquets
Given an integer arraybloomDay, an integermand an integerk.We need to makembouquets. To make a bouquet,you need to usekadjacent flowersfrom the garden.The garden consists ofnflowers, theithflower will bloom in thebloomDay[i]and then can...原创 2020-06-14 12:22:47 · 308 阅读 · 0 评论 -
Divide Chocolate
You have one chocolate bar that consists of some chunks. Each chunk has its own sweetness given by the arraysweetness.You want to share the chocolate with yourKfriends so you start cutting the chocolate bar intoK+1pieces usingKcuts, each piece con...原创 2020-05-25 07:52:16 · 429 阅读 · 0 评论 -
Minimize Max Distance to Gas Station
On a horizontal number line, we have gas stations at positionsstations[0], stations[1], ..., stations[N-1], whereN = stations.length.Now, we addKmore gas stations so thatD, the maximum distance...原创 2020-04-22 14:47:36 · 245 阅读 · 0 评论 -
Split Array Largest Sum
Given an array which consists of non-negative integers and an integerm, you can split the array intomnon-empty continuous subarrays. Write an algorithm to minimize the largest sum among thesemsub...原创 2020-03-30 08:57:59 · 303 阅读 · 0 评论 -
Capacity To Ship Packages Within D Days
Thei-th package on the conveyor belt has a weight ofweights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given byweights). We may not load more weight than the m...原创 2020-02-26 13:15:42 · 375 阅读 · 0 评论 -
Maximum Average Subarray II
Given an array with positive and negative numbers, find themaximum average subarraywhich length should be greater or equal to given lengthk.ExampleExample 1:Input:[1,12,-5,-6,50,3]3Output...原创 2019-12-06 12:31:35 · 318 阅读 · 0 评论 -
Find the Duplicate Number
Given an arraynumscontainingn + 1integers where each integer is between1andn(inclusive), guarantee that at least one duplicate number must exist. Assume that there is only one duplicate number...原创 2016-08-12 07:09:04 · 391 阅读 · 0 评论 -
Copy Books II
Givennbooks and each book has the same number of pages. There arekpersons to copy these books and thei-thperson needstimes[i]minutes to copy a book.Each person can copy any number of books a...原创 2019-12-06 13:40:03 · 405 阅读 · 0 评论 -
Copy Books
Givennbooks and thei-thbook haspages[i]pages. There arekpersons to copy these books.These books list in a row and each person can claim a continous range of books. For example, one copier ca...原创 2019-12-06 13:06:18 · 1824 阅读 · 0 评论 -
Wood Cut
Given n pieces of wood with lengthL[i](integer array). Cut them into small pieces to guarantee you could have equal or more than k pieces with the same length. What is the longest length you can get...原创 2019-12-06 11:29:57 · 622 阅读 · 0 评论 -
二分答案总结
二分答案是binary search里面比较难的题型,也就是,直接求一个最值很难,但是我们可以很简单的在解空间做判定性问题,比如能不能,行不行,大了还是小了,return true or false,从而缩小解空间,记住,这种方法有个前提条件就是有单调递增或者递减的性质,才能用。这也是binary search使用的条件;Wood Cut有一些原木,现在想把这些木头切割成一些长度相同的小段...原创 2020-01-17 01:51:36 · 2475 阅读 · 0 评论