diff --git a/programmers/같은 숫자는 싫어/solution.java b/programmers/같은 숫자는 싫어/solution.java new file mode 100644 index 0000000..ca4fcdb --- /dev/null +++ b/programmers/같은 숫자는 싫어/solution.java @@ -0,0 +1,16 @@ +// [문제 링크]: https://school.programmers.co.kr/learn/courses/30/lessons/12906# + +import java.util.*; +public class Solution { + public int[] solution(int []arr) { + Queue q = new LinkedList(); + for(int b : arr){ + Object peek = ((LinkedList)q).peekLast(); + if(peek != null && b == (int)peek) continue; + else { + q.add(b); + } + }//list 상태에서도 가능하지만 array가 수요이니 array로 변환합니다. + return q.stream().mapToInt(Integer::intValue).toArray(); + } +} \ No newline at end of file