본문 바로가기
반응형

LeetCode25

Intersection of Two Arrays II [leetcode] 문제 풀이 설명 어려운 문제는 아니였다. 그래도 역시 생각보다 오래 고민했다. 한 시간 안되게? 일단 교집합이라고 문제 제목이 나와있기 때문에 단순히 교집합으로 풀어야 겠다 생각하면 안된다. 무구한 삽질을 이미 다른 문제를 통해 경험해 봤기 때문에 python이 제공하는 set 연산을 하면 안된다는걸 알고 있다. 첫번째 케이스의 경우 set 연산으로 수행할 경우 [2,2] 가 아니라 [2]로 나오게 된다. → 교집합 연산을 위해서는 리스트가 아니라 집합으로 먼저 바뀌어야 하고 그럼 [1,2,2,1] → [1,2] 로 중복이 제거 나는 이렇게 풀었다 (코드를 보면 알겠지만) 크기가 작은 리스트의 숫자를 꺼낸다. 해당 숫자가 다른 리스트에 들어있는지 판단한다. 들어 있다면 해당 숫자를 크기가 큰쪽에서 제거한.. 2021. 9. 18.
Reverse Nodes in k-Group [LeetCode] 문제 풀이 정리 Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes, in the end, should remain as it is. You may not alter the values in the list's nodes, only nodes themselves may be changed. Example 1: Input.. 2021. 7. 18.
Find Peak Element [LeetCode] 문제 풀이 정리 Find Peak Element A peak element is an element that is strictly greater than its neighbors. Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks. You may imagine that nums[-1] = nums[n] = -∞. You must write an algorithm that runs in O(log n) time. Example 1: Input: nums = [1,2,3,1] Output: 2 Ex.. 2021. 7. 14.
Isomorphic Strings [LeetCode] 문제 풀이 정리 문제 Given two strings s and t, determine if they are isomorphic. Two strings s and t are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself. Example 1: Input: s = "egg", t = "add" Outpu.. 2021. 7. 12.
Find Median from Data Stream [LeetCode] 문제 풀이 정리 문제 The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle values. For example, for arr = [2,3,4], the median is 3. For example, for arr = [2,3], the median is (2 + 3) / 2 = 2.5. Implement the MedianFinder class: MedianFinder() initializes the MedianFinder object. void addNum(int nu.. 2021. 7. 12.
Reduce Array Size to The Half [LeetCode] 문제 풀이 정리 Given an array arr. You can choose a set of integers and remove all the occurrences of these integers in the array. Return the minimum size of the set so that at least half of the integers of the array are removed. Example 1: Input: arr = [3,3,3,3,5,5,5,2,2,7] Output: 2 Explanation: Choosing {3,7} will make the new array [5,5,5,2,2] which has size 5 (i.e equal to half of the size of the.. 2021. 7. 7.
Reshape the Matrix [LeetCode] 문제 풀이 정리 In MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with a different size r x c keeping its original data. You are given an m x n matrix mat and two integers r and c representing the row number and column number of the wanted reshaped matrix. The reshaped matrix should be filled with all the elements of the original matrix in the same row.. 2021. 7. 6.
반응형