package codingTest; import java.util.*; import java.util.stream.Collectors; public class module2 { public static void main(String[] args) { //문제풀이 기본 양식 Solution s = new Solution(); String[] answer = {}; // String[] rooms= {"[1234]None,Of,People,Here", "[5678]Wow"}; int target = 1234; System.out.println(s.solution01(new String[] {"I 16","D 1"})); System.out.println(s.solution02(new String[] {"I 16","D 1"})); System.out.println(s.solution03(new String[] {"I 16","D 1"})); } public static void tmpArchive() { //int array int[] arr1 = new int [1]; int[] arr2 = {}; String[] arr3 = {}; Arrays.sort(arr1); //오름차순 Arrays.stream(arr1).sum(); //합계 Arrays.stream(arr1).filter(s -> true); //filter //stream filter 후 list 반환 //ArrayList alreadyRankUser = (ArrayList) arr1.stream().filter(t -> t[0].equals(userName) && Integer.parseInt(t[1]) >= userScore).collect(Collectors.toList()); List list1 = new ArrayList(); list1.add(new Integer[][] {{1,3}}); //List List list2 = new ArrayList(); int index1 = 0; list2.add(index1, 0); list2.remove(index1); for (Integer integer : list2) { System.out.println(integer); } //List Sort Collections.sort(list2,new Comparator() { public int compare(Object o1,Object o2) { // Object v1 = map.get(o1); // Object v2 = map.get(o2); // // if(v1.equals(v2)) { // return ((Comparable) o1).compareTo(o2); // } return ((Comparable) o1).compareTo(o2); } }); //map 선언 -> key 중복 x HashMap map = new HashMap(); HashMap> ma2 = new HashMap>(); //ma2.put("aa", new List); for(String key : map.keySet()) { } //HashSet -- 중복 미허용 Set set1 = new HashSet(); //Stack Stack stack = new Stack(); stack.add(null); //넣기 stack.empty(); //비었는지 확인 stack.peek(); //stack 최상단 값 stack.pop(); //stack 빼기 //Queue Queue queue = new LinkedList<>(); queue.add(null); //넣기 queue.isEmpty(); //비었는지 확인 queue.peek(); //queue 나올 값 queue.poll(); //queue 빼기 //Deque ArrayDeque dq = new ArrayDeque<>(50505); dq.isEmpty(); dq.add(null); dq.addFirst(null); dq.addLast(null); dq.peekFirst(); dq.peekLast(); dq.pollFirst(); dq.pollLast(); //PriorityQueue PriorityQueue maxPq = new PriorityQueue(Collections.reverseOrder()); //최대우선순위큐 PriorityQueue minPq = new PriorityQueue(); //최소우선순위큐 PriorityQueue> pqh = new PriorityQueue>(new Comparator>() { @Override public int compare(HashMap o1, HashMap o2) { int size1 = Integer.parseInt(o1.get("size")); int size2 = Integer.parseInt(o2.get("size")); String name1 = o1.get("name"); String name2 = o2.get("name"); if(size1 != size2) { return ((Comparable) size1).compareTo(size2); } else { return ((Comparable) name1).compareTo(name2); } } }); maxPq.add(null); maxPq.peek(); //head maxPq.poll(); //빼기 maxPq.isEmpty(); //비었는지 maxPq.remove(); //삭제 //변환 //List -> int[]; int[] arr99 = {}; List list99 = new ArrayList(); arr99 = list99.stream().mapToInt(i->i).toArray(); //int[] -> List int[] arr100 = {}; List list100 = Arrays.stream(arr100).boxed().collect(Collectors.toList()); //Integer[] -> List Integer[] arr101 = {}; List list101 = Arrays.asList(arr101); //String String str1 = "ABC"; str1.charAt(1); } public static boolean isPrime(int num){ for(int i=2; i<=num/2; i++){ if(num % i == 0) return false; } return true; } static ArrayList[] a; static boolean[] c; public static void dfs(int x) { if (c[x]) { return; } c[x] = true; System.out.print(x + " "); for (int y : a[x]) { if (c[y] == false) { dfs(y); } } } public static void bfs(int start) { Queue q = new LinkedList(); q.add(start); c[start] = true; while (!q.isEmpty()) { int x = q.remove(); System.out.print(x + " "); for (int y : a[x]) { if (c[y] == false) { c[y] = true; q.add(y); } } } } public boolean BinarySearch(int []arr, int len, int key){ int start = 0; int end = len-1; int mid; while(end - start >= 0) { mid = (start + end) / 2; //중앙 값 if (arr[mid] == key) { //key값을 찾았을때 return true; } else if (arr[mid] > key) { //key값이 mid의 값보다 작을때 (왼쪽으로) end = mid - 1; } else { //key값이 mid의 값보다 클때 (오른쪽으로) start = mid + 1; } } return false; } static boolean isStringInt(String a) { try { Integer.parseInt(a); return true; } catch (NumberFormatException ex) { return false; } } } class Solution { public static void solution01() { } public static void solution02() { } public static void solution03() { } }