[leetcode 347] Top K Frequent Elements-heapq
문제Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]Example 2:Input: nums = [1], k = 1Output: [1]Example 3:Input: nums = [1,2,1,2,1,2,3,1,3,2], k = 2Output: [1,2] Constraints:1 첫번째 풀이: 단순하게 처리 가능함class Solution: def topKFrequent(self, nums: List[int], k: int) -> ..
[leetcode 445] Add Two Numbers II
문제You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example 1:Input: l1 = [7,2,4,3], l2 = [5,6,4]Output: [7,8,0,7]Example 2:Input: ..
[leetcode 209] Minimum Size Subarray Sum - 슬라이딩 윈도우
leetcode 209 문제Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose sum is greater than or equal to target. If there is no such subarray, return 0 instead. Example 1:Input: target = 7, nums = [2,3,1,2,4,3]Output: 2Explanation: The subarray [4,3] has the minimal length under the problem constraint.Example 2:Input: target = 4, nums =..