[ LeetCode ] 27 Remove Element

codesver·2023년 3월 27일
0

LeetCode

목록 보기
11/24
post-thumbnail

Link | LeetCode 27번 문제 : Remove Element

📌 About

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

요약하자면 주어진 nums의 앞에서부터 val들을 뒤로 옮긴다..

그리고 val이 아닌 숫자들의 갯수를 반환하면 된다.

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

📌 Code

GitHub Repository

fun removeElement(nums: IntArray, `val`: Int): Int =
    nums.filter { it != `val` }.mapIndexed { idx, num -> nums[idx] = num }.size
profile
Hello, Devs!

0개의 댓글