随笔分类 -  pq

703. Kth Largest Element in a Stream
摘要:Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. Your KthLargest class will have a constructor w... 阅读全文

posted @ 2018-11-09 06:36 猪猪🐷

857. Minimum Cost to Hire K Workers
摘要:There are N workers. The i-th worker has a quality[i] and a minimum wage expectation wage[i]. Now we want to hire exactly K workers to form a paid group. When hiring a group of K workers, we must ... 阅读全文

posted @ 2018-11-08 17:00 猪猪🐷

373 Find K Pairs with Smallest Sums
摘要:https://leetcode.com/problems/find-k-pairs-with-smallest-sums/discuss/84551/simple-Java-O(KlogK)-solution-with-explanation public class Solution { public List kSmallestPairs(int[] nums1, int[... 阅读全文

posted @ 2018-11-08 16:40 猪猪🐷

295 Find Median from Data Stream
摘要:Approach #3 Two Heaps! [Accepted] Intuition The above two approaches gave us some valuable insights on how to tackle this problem. Concretely, one can 阅读全文

posted @ 2018-11-08 02:21 猪猪🐷

480. Sliding Window Median
摘要:Approach #2 Two Heaps! (Lazy Removal) [Accepted] Intuition The idea is the same as Approach #3 from 295. Find Median From Data Stream. The only additi 阅读全文

posted @ 2018-11-08 02:19 猪猪🐷

215. Kth Largest Element in an Array
摘要:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Example 1: Input: [3,2,1,5,6,4] and k = 2 Output: 5 Examp... 阅读全文

posted @ 2018-11-07 04:58 猪猪🐷

787. Cheapest Flights Within K Stops
摘要:There are n cities connected by m flights. Each fight starts from city u and arrives at v with a price w. Now given all the cities and flights, togeth 阅读全文

posted @ 2018-11-06 08:50 猪猪🐷

407. Trapping Rain Water II
摘要:Example: The above image represents the elevation map [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]] before the rain. After the rain, water is trapped be 阅读全文

posted @ 2018-11-06 08:49 猪猪🐷

778. Swim in Rising Water
摘要:On an N x N grid, each square grid[i][j] represents the elevation at that point (i,j). Now rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to anothe... 阅读全文

posted @ 2018-11-06 08:45 猪猪🐷

373. Find K Pairs with Smallest Sums
摘要:You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define a pair (u,v) which consists of one element from the first array and one element from the second arr... 阅读全文

posted @ 2018-11-06 08:42 猪猪🐷

499. The Maze III
摘要:There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolling up (u), down (d), left (l) or right (r), but it won't stop rolling until hitting a wall. When th... 阅读全文

posted @ 2018-11-06 08:42 猪猪🐷

264. Ugly Number II
摘要:Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example: Input: n = 10 Output: 12 Explanation: 1, 2, 3, 4, 5, 6, 8, 9, 10, 1... 阅读全文

posted @ 2018-11-06 08:41 猪猪🐷

668. Kth Smallest Number in Multiplication Table
摘要:Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number quickly from the multiplication table? Given the height m and the length n of a m * n Multiplicati... 阅读全文

posted @ 2018-11-06 08:40 猪猪🐷

313. Super Ugly Number
摘要:Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. Example: Input: n = 12, primes = [2,7,... 阅读全文

posted @ 2018-11-06 08:40 猪猪🐷

378. Kth Smallest Element in a Sorted Matrix
摘要:Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not t... 阅读全文

posted @ 2018-11-06 08:39 猪猪🐷

855. Exam Room
摘要:In an exam room, there are N seats in a single row, numbered 0, 1, 2, ..., N-1. When a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there ... 阅读全文

posted @ 2018-09-25 04:25 猪猪🐷

774. Minimize Max Distance to Gas Station
摘要:On a horizontal number line, we have gas stations at positions stations[0], stations[1], ..., stations[N-1], where N = stations.length. Now, we add K more gas stations so that D, the maximum distanc... 阅读全文

posted @ 2018-09-25 04:23 猪猪🐷

857. Minimum Cost to Hire K Workers
摘要:857. Minimum Cost to Hire K Workers There are N workers. The i-th worker has a quality[i] and a minimum wage expectation wage[i]. Now we want to hire exactly K workers to form a paid group. When hi... 阅读全文

posted @ 2018-09-17 11:59 猪猪🐷

top k closest points to origin, k closest points to <0,0,0>
摘要:大班文档有java solution 强化 5 x.y z is similar 阅读全文

posted @ 2018-08-11 03:47 猪猪&#128055;

347. Top K Frequent Elements
摘要:Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input 阅读全文

posted @ 2018-08-10 15:19 猪猪&#128055;

导航