본문 바로가기

🧩 Algorithm19

LeetCode : 27. Remove Element 문제 링크 Remove Element - LeetCode Can you solve this real interview question? Remove Element - Given an integer array nums and an integer val, remove all occurrences of val in nums in-place [https://en.wikipedia.org/wiki/In-place_algorithm]. The order of the elements may be changed. Then r leetcode.com 문제 먼저 읽기 nums 정수 배열과 val 정수 1개가 주어진다. val과 같은 수를 nums에서 제거한다. 제거된 정수 외의 다른 수만 남긴 결과를 nums 배열에 저장.. 2023. 8. 25.
LeatCode : 88. Merge Sorted Array 문제 링크 Merge Sorted Array - LeetCode Can you solve this real interview question? Merge Sorted Array - You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 an leetcode.com 문제 먼저 읽기 오름차순으로 정렬된 숫자 배열 2개 nums1, num2 가 주어진다. 이 두 배열을 nums1 배열 안에 오름차순으로 합쳐야 한다. 현재 nums1.. 2023. 8. 24.
BJ2075 : N번째 큰 수 https://www.acmicpc.net/problem/2075 2075번: N번째 큰 수 첫째 줄에 N(1 ≤ N ≤ 1,500)이 주어진다. 다음 N개의 줄에는 각 줄마다 N개의 수가 주어진다. 표에 적힌 수는 -10억보다 크거나 같고, 10억보다 작거나 같은 정수이다. www.acmicpc.net 접근 방법 가볍게 풀 수 있는 문제인가 싶었지만 기본 배열로는 풀 수가 없다. 함께 공부하는 동료의 조언으로 우선순위 큐를 시도하였다. 우선순위 큐를 활용하여 풀면 시간복잡도가 유리하여 편리하게 풀 수 있다. 참조링크 👉 우선순위 큐의 시간 복잡도 우선순위 큐는 완전 이진트리 형태의 힙을 이용해 구현할 수 있다. 우선순위 큐의 삽입과 삭제는 𝑂(𝑙𝑜𝑔𝑁)의 시간 복잡도를 가진다. 우선순위 큐를 이용한 정.. 2023. 2. 8.