같은 숫자는 싫어 JAVA

sundays·2022년 8월 17일
0

문제

import java.util.*;

public class Solution {
    public int[] solution(int []arr) {
        Stack<Integer> s = new Stack<>();
        for (int x : arr) {
            if (s.isEmpty()) {
                s.push(x);
            } else {
                if (s.peek() != x) {
                    s.push(x);
                }
            }
        }

        int[] answer = new int[s.size()];
        for (int i = s.size() - 1; i >= 0; i--) {
            answer[i] = s.pop();
        }
        return answer;
    }
}

채점 결과
정확성: 71.9
효율성: 28.1
합계: 100.0 / 100.0

문제에서 주어진 그대로 풀었다. 스택/ 큐 문제길래 스택 사용해봤는데,
다른 분들 풀이 보니까 다들 스트림 함수 쓴다. 내 눈에는 스트림 함수 왜이렇게 한눈에 안들어오는건지. 익숙해 질 수 있도록 추가해봐야겠다.

profile
develop life

0개의 댓글