Notice
Recent Posts
Recent Comments
Today
Total
01-25 23:16
Link
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Partially Committed

[๋ฐฐ์—ด] ๊ฐ™์€ ์ˆซ์ž๋Š” ์‹ซ์–ด (JAVA) ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm || ๋ฌธ์ œํ’€์ด/PS

[๋ฐฐ์—ด] ๊ฐ™์€ ์ˆซ์ž๋Š” ์‹ซ์–ด (JAVA)

WonderJay 2022. 9. 2. 23:21
728x90
๋ฐ˜์‘ํ˜•
SMALL

https://school.programmers.co.kr/learn/courses/30/lessons/12906?language=java 

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

ํ’€์ด1

import java.io.IOException;
import java.util.ArrayList;

class Solution {
    public int[] solution(int []arr) throws IOException {
        int[] answer = {};
        ArrayList<Integer> arrlist = new ArrayList<Integer>();
        int backup = -1;
        for(int i = 0 ; i < arr.length; i++){
            if(backup != arr[i]){
                arrlist.add(arr[i]);
                backup = arr[i];
            }
        }
        answer = new int[arrlist.size()];
        for(int i = 0 ; i < arrlist.size(); i++){
            answer[i] = arrlist.get(i);
        }
        return answer;
    }
}

 

728x90
๋ฐ˜์‘ํ˜•
LIST
Comments