Algorithm

Algorithm/Programmers

[Programmers] LV2. 124나라의 숫자

// LV2. 124 나라의 숫자 public static String solution_124Country(int n) { StringBuffer sb = new StringBuffer(); while(n > 0){ int su = n%3==0?3:n%3; sb.append((int)Math.pow(2,su-1)); n /= 3; if(su==3) n -= 1; } return sb.reverse().toString(); }

Algorithm/Programmers

[Programmers] LV2. 멀쩡한 사각형

// LV2. 멀쩡한 사각형 public static long solution_normalSquare(long w, long h) { long answer = w * h; // 첫 사각형 크기 long gcd = 1, idx = w; while (1 < idx) { // 공약수 구하기 if (w % idx == 0 && h % idx == 0) { gcd *= idx; w /= idx; h /= idx; idx = w; } else idx--; } long gcd2 = BigInteger.valueOf(w).gcd(BigInteger.valueOf(h)).longValue(); return answer - gcd * (w + h - 1); }

Algorithm/Programmers

[Programmers] LV2. 오픈채팅방

// LV2. 오픈채팅방 public static String[] solution_openKaKao(String[] record) { Map usermap = new HashMap(); List answer = new ArrayList(); for (String str : record) { String[] temparr = str.split(" "); if ("Enter".equals(temparr[0])) { usermap.put(temparr[1], temparr[2]); answer.add(temparr[1] + "/님이 들어왔습니다."); } else if ("Leave".equals(temparr[0])) { answer.add(temparr[1] + "/님이 나갔습니다."); } else if..

Algorithm/Programmers

[Programmers] LV2. 더 맵게

scoville int배열을 우선순위큐로 변환하여 사용 // LV.2 더 맵게 public static int solution_moreSpicy(int[] scoville, int K) { int answer = 0; PriorityQueue heap = Arrays.stream(scoville).boxed() .collect(Collectors.toCollection(PriorityQueue::new)); while (heap.peek() != null && heap.peek() 0 ? answer : -1..

Algorithm/Programmers

[Programmers] LV2. 문자열 압축

문자가 반복되는 갯수 만큼 숫자로 표기하여 문자열 크기를 가장작게 줄인 길이를 반환하는 문제 https://school.programmers.co.kr/learn/courses/30/lessons/60057 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr // LV.2 문자열 압축 public static int solution_TextCompression(String s) { int answer = s.length(); for (int i = 1; i 0) { // 같은문자 카운트 끝났으면 줄어든 문자 수 계산 // 줄어든 문자 수 계산 : (잘린 단위 ..

Bogass
'Algorithm' 카테고리의 글 목록 (5 Page)