[자바JAVA]Missing Numbers 해커랭크
💡 핵심 요약 (TL;DR)
'Missing Numbers 해커랭크' 알고리즘 문제의 요구사항을 분석하고 최적의 자료구조와 연산 방식을 적용해 구현한 풀이다. arr과 brr을 비교하여 brr에는 있지만 arr에는 없는 숫자(Missing Numbers)를 배열로 나타내는 문제.을 적용해 성능을 최적화했다.
문제
arr과 brr을 비교하여 brr에는 있지만 arr에는 없는 숫자(Missing Numbers)를 배열로 나타내는 문제.
Given two arrays of integers, find which elements in the second array are missing from the first array.
Function Description : Complete the missingNumbers function in the editor below. It should return a sorted array of missing numbers.
missingNumbers has the following parameter(s):
- int arr[n]: the array with missing numbers
- int brr[m]: the original array of numbers
Returns : int[]: an array of integers
- 입출력예시
1 | //입력 |
코드
두 배열을 각각 HashMap에 담은 뒤 (brr 해쉬맵 - arr 해쉬맵)을 통해 빠진 숫자를 효율적으로 찾을 수 있다.
1 | public class MissingNumbers { |
참고
해커랭크의 다른 문제 풀이가 보고싶다면?
[자바JAVA]Missing Numbers 해커랭크
https://sowon-dev.github.io/2021/03/06/210307al-hackerrank-MissingNumbers/