Skip to content

Instantly share code, notes, and snippets.

@dalcon10028
Created July 7, 2020 11:29
Show Gist options
  • Save dalcon10028/17ea7a1cffad9ca4c0886d16c845c97c to your computer and use it in GitHub Desktop.
Save dalcon10028/17ea7a1cffad9ca4c0886d16c845c97c to your computer and use it in GitHub Desktop.
프로그래머스 코딩테스트 연습 Level1 - 같은 숫자는 싫어 [ Java ]
import java.util.LinkedList;
public class Solution {
public static void main(String[] args) {
int[] arr = new int[]{1, 1, 3, 3, 0, 1, 1};
int[] r = solution(arr);
for (int i : r)
System.out.println(i);
}
static int[] solution(int[] arr) {
LinkedList<Integer> list = new LinkedList<>();
for (Integer i : arr) {
if(!list.isEmpty() && list.getLast()==i)
continue;
list.add(i);
}
return list.stream().mapToInt(i->i).toArray();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment