Algorithm/Programmers

Algorithm/Programmers

[Programmers] LV2. 카펫

// LV2. 카펫 public static int[] solution_carpet(int brown, int yellow) { int idx = IntStream.rangeClosed(1,(int)Math.sqrt(yellow)) .filter(i -> yellow % i == 0) .findFirst().getAsInt(); return new int[]{yellow/idx+2,idx+2}; }

Algorithm/Programmers

[Programmers] LV.2. 위장

// lv2. 위장 public static int solution_camouflage(String[][] clothes) { int answer = 1; Map list = new HashMap(); for (String[] s1 : clothes){ if(list.containsKey(s1[1])) list.put(s1[1],list.get(s1[1])+1); else list.put(s1[1],1); } for(String s : list.keySet()){ answer *= list.get(s)+1; } return answer-1; }

Algorithm/Programmers

[Programmers] LV2. 다리를 지나가는 트럭

// LV2. 다리를 지나가는 트럭 public static int solution_truck(int bridge_length, int weight, int[] truck_weights) { int answer = 1; Queue bridgeQ = new LinkedList(); int idx = 1; for(int i=0;i

Algorithm/Programmers

[Programmers] LV2. 프린터

//LV2. 프린터 public static int solution_printer(int[] priorities, int location) { LinkedList list = new LinkedList(); for(int i : priorities) list.add(new Integer(i)); Integer idx = list.get(location); int cnt = 1; while(0 0){ flag = true; break; } } if(flag) list.addLast(i); else{ if(i..

Algorithm/Programmers

[Programmers] LV2. 짝지어 제거하기

//LV2. 짝지어 제거하기 public static int solution_pair_remove(String s){ //int answer = -1; String[] stringarr = s.split(""); Stack st = new Stack(); for(String str :stringarr ){ if(st.size()!=0&&str.equals(st.peek())){ st.pop(); }else if(st.size()>stringarr.length/2){ return 0; }else{ st.push(str); } } return st.size()==0?1:0; }

Algorithm/Programmers

[Programmers] LV2. 전화번호 목록

// LV2. 전화번호부 public static boolean solution_phonebook(String[] phone_book) { boolean answer = true; PriorityQueue queue = Arrays.stream(phone_book).collect(Collectors.toCollection(PriorityQueue::new)); while(1 < queue.size()){ String str = queue.poll(); if(str.startsWith(queue.peek())||queue.peek().startsWith(str)){ answer = false; break; } } return answer; }

Algorithm/Programmers

[Programmers] LV2. 모음사전

//LV2. 모음사전 enum vowel{A,E,I,O,U}; public static int solution_vowel_dictionary(String word) { int answer = 0; int[] jump = new int[5]; for(int i=0;i

Algorithm/Programmers

[Programmers] LV2.n^2배열 자르기

// LV2.n^2배열 자르기 public static int[] solution_slice_array(int n, long left, long right) { int[] answer = new int[(int)(right-left+1)]; int idx = 0; for(long i = (long)Math.floor(left/n);i

Bogass
'Algorithm/Programmers' 카테고리의 글 목록 (2 Page)