769/768. Max Chunks To Make Sorted 1 and 2
摘要:769 题意: 一个数组是 0-N-1 的组合, 数组可以被分成多个chunks, 主要chunks 内部排序好了,整个数组就可以排序好。 768:题目: 和768 类似,只是数组是任意的,不是0-N-1的组合。 比较两个子数组 是否一样arr1: [1 2 1 2]arr2: [2 2 1 1]
阅读全文
posted @
2018-10-28 13:23
KeepAC
阅读(109)
推荐(0)
493. Reverse Pairs
摘要:题意: Given an array nums, we call (i, j) an important reverse pair if i < j and nums[i] > 2*nums[j]. 这种不能破坏 i 和j “相对关系” 的情况去统计一些结果的题,都可以考虑merge sort. m
阅读全文
posted @
2018-10-22 05:19
KeepAC
阅读(165)
推荐(0)
327. Count of Range Sum
摘要:Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Range sum S(i, j) is defined as the sum of the eleme
阅读全文
posted @
2018-10-22 05:03
KeepAC
阅读(105)
推荐(0)
315. Count of Smaller Numbers After Self
摘要:这题 和 327. Count of Range Sum and 493. Reverse Pairs 几乎一样的解法,都属于hard 题, 可以用 merge sort, segment tree 和 BST 去求解。 注意如果自己去实现简单的BST, 在数组已经排序好的情况下 比 [1 2 3
阅读全文
posted @
2018-10-22 04:10
KeepAC
阅读(150)
推荐(0)
406. Queue Reconstruction by Height
摘要:这题本质上是贪心法, 一个原则 “只有比你身高高的或者相等的才对你有影响,插入任何比你小的人都对你没影响” 因此从大到小排列,先处理大的,再处理小的。每次处理时K 就是插入的位置,因为前面人的身高都比你高或者一样,所以你的K 是多少就决定了你的下标。 people: [[7,0], [4,4], [
阅读全文
posted @
2018-10-20 14:34
KeepAC
阅读(74)
推荐(0)