[ LeetCode ] 26 Remove Duplicates from Sorted Array

codesver·2023년 3월 26일
0

LeetCode

목록 보기
10/24
post-thumbnail

Link | LeetCode 26번 문제 Remove Duplicates from Sorted Array

📌 About

이 문제는 Custom Judge 문제로 몇 가지를 따라야한다.

요약하자면 주어진 nums의 앞에서부터 미중복 숫자들로 차례대로 교체한다.

그리고 미중복 숫자들의 갯수를 반환하면 된다.

예를 들어 [1, 1, 2, 3, 3, 4, 4, 4]이면 [1, 2, 3, 4...]로 바꾸고 4를 반환한다.

📌 Code

GitHub Repository

fun removeDuplicates(nums: IntArray): Int = nums
    .distinct()
    .onEachIndexed { idx, num -> nums[idx] = num }.size
profile
Hello, Devs!

0개의 댓글