힙큐4 [Leetcode 215] - Kth Largest Element in an Array w/ Python Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Can you solve it without sorting? 숫자가 들어가 있는 배열과 정수 k가 주어졌을때 정렬 없이 배열에서 k번째로 큰 숫자를 리턴하는 문제 https://leetcode.com/problems/kth-largest-element-in-an-array/description/ Example 1: Input: nums = [3,2,1,5,6,4], k = 2 Outp.. 2024. 4. 16. [Leetcode 973] - K Closest Points to Origin w/ Python Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0). The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)2 + (y1 - y2)2). You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in). [x, y]의 좌표가 들어있는 .. 2024. 4. 16. [Leetcode 1046] - Last Stone Weight w/ Python You are given an array of integers stones where stones[i] is the weight of the ith stone. We are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them together. Suppose the heaviest two stones have weights x and y with x 2024. 4. 16. [Leetcode 703] - Kth Largest Element in a Stream w/ Python 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. Implement KthLargest class: 1. KthLargest(int k, int[] nums) Initializes the object with the integer k and the stream of integers nums. 2. int add(int val) Appends the integer val to the stream and returns the element representing the kth largest .. 2024. 4. 16. 이전 1 다음 반응형