Skip to content

Latest commit

ย 

History

History
28 lines (22 loc) ยท 665 Bytes

File metadata and controls

28 lines (22 loc) ยท 665 Bytes

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Level1 : ์—ฐ์Šต๋ฌธ์ œ ๊ฐ™์€ ์ˆซ์ž๋Š” ์‹ซ์–ด

import java.util.ArrayList;

public class Solution {
    public int[] solution(int[] arr) {
        int[] answer = {};        
        ArrayList<Integer> nums = new ArrayList<>();
        
        for(int num : arr){
            if(nums.isEmpty() || nums.get(nums.size()-1) != num){
                nums.add(num);   
            }
        }
        
        answer = new int[nums.size()];
        int size = 0;
        for(int num : nums){
            answer[size++] = num;
        }

        return answer;
    }
}