🙈

⃝ 동글동글 ⃝

🪐ᐩ˖ 🍎
728x90
반응형
SMALL

프로그래머스 25

[프로그래머스 고득점 Kit] 프로세스 - Stack/Queue - Lv2

⭐️ 코드 import java.util.*; class Solution { private static class Node { int priority; int idx; public Node(int priority, int idx) { this.priority = priority; this.idx = idx; } } public int solution(int[] priorities, int location) { int answer = 0; ArrayDeque queue = new ArrayDeque(); for (int i = 0; i < priorities.length; i++) { queue.add(new Node(priorities[i], i)); } // 숫자가 높을 수록 우선순위가 높음 while..

[프로그래머스 고득점 Kit] 기능개발 - Stack/Queue - Lv2

⭐️ 코드 (Queue 이용) import java.util.*; class Solution { public int[] solution(int[] progresses, int[] speeds) { ArrayDeque queue = new ArrayDeque(); ArrayDeque speedsQueue = new ArrayDeque(); for (int i = 0; i < progresses.length; i++) { queue.addLast(progresses[i]); speedsQueue.addLast(speeds[i]); } ArrayList arrayList = new ArrayList(); while (!queue.isEmpty()) { for (int i = 0; i < queue.size()..

[프로그래머스 고득점 Kit] 베스트앨범 - Hash(해시) - Lv3

⭐️ 코드 (HashSet 이용) 정답 코드지만 직접 풀어보면서 출력해 봤던 테스트 코드!! 이번 문제는 완전 리스트와 해시맵의 중첩이었다... import java.util.*; public class 베스트앨범 { static class Solution { private static class Node { int idx; String genre; int play; public Node(int idx, String genre, int play) { this.idx = idx; this.genre = genre; this.play = play; } @Override public String toString() { return "Node{" + "idx=" + idx + ", genre='" + genre..

[프로그래머스 고득점 Kit] 의상 - Hash(해시) - Lv2

⭐️ 코드 (HashSet 이용) 1. HashMap에 옷의 종류별로 개수를 카운트한다. 2. 해당 옷을 안 입는 경우도 있기 때문에 경우의 수 + 1을 해준다. 3. 모든 옷을 안 입는 경우는 없기 때문에 결과 -1을 해서 개수 세기! import java.util.*; class Solution { public int solution(String[][] clothes) { int answer = 0; HashMap hashMap = new HashMap(); for (int i = 0; i < clothes.length; i++) { hashMap.put(clothes[i][1], hashMap.getOrDefault(clothes[i][1], 0) + 1); } int count = 1; for (..

[프로그래머스 고득점 Kit] 전화번호 목록 - Hash(해시) - Lv2

⭐️ 코드 (HashSet 이용) import java.util.*; class Solution { public boolean solution(String[] phone_book) { boolean answer = true; HashSet hashSet = new HashSet(); for (int i = 0; i < phone_book.length; i++) { hashSet.add(phone_book[i]); } for (int i = 0; i < phone_book.length; i++) { for (int j = 0; j < phone_book[i].length(); j++) { if (hashSet.contains(phone_book[i].substring(0, j))) { return fals..

[프로그래머스/Programmers] 구명보트 (Java - Greedy - Lv2)

구명보트 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ⭐️ 코드 import java.util.Arrays; class Solution { public int solution(int[] people, int limit) { int answer = 0; Arrays.sort(people); int j = 0; for (int i = people.length-1; i>=j; i--) { if (people[j] + people[i] =j; i--) { if (people[j] + people[i]

[프로그래머스/Programmers] 카펫 (Java - 완전탐색 - Lv2)

카펫 - 완전탐색 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ⭐️ 코드 class Solution { public int[] solution(int brown, int yellow) { int[] answer = new int[2]; int tileSum = brown+yellow; // 전체 타일 개수 int yellow_sqrt = (int)Math.sqrt(yellow); for(int i = yellow_sqrt; i>0; i--) { for (int j = yellow_sqrt; j 0; i--) { for (int j = yellow_sqr..

[프로그래머스/Programmers] 가장 큰 수 (Java - 정렬 - Lv2)

가장 큰 수 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ⭐️ 코드 - 프로그래머스에서 빌드할 때는 출력문은 다 지우고 하셔야 합니다. package Programmers.Level_2; import java.util.*; public class PL2_17 { // Level2 가장 큰 수 public String solution(int[] numbers) { // numbers 배열을 String 변환 String[] sArr = new String[numbers.length]; for (int i = 0; i < sArr.length; i++) {..

[프로그래머스/Programmers] 영어 끝말잇기 (Java - HashSet - Lv2)

영어 끝말잇기 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ⭐️ 코드 import java.util.HashMap; class Solution { public int[] solution(int n, String[] words) { int[] answer = new int[2]; HashMap hashMap = new HashMap(); for (int i = 0; i 0 && !(words[i].charAt(..

[프로그래머스/Programmers] 짝지어 제거하기 (Java - Stack - Lv2)

짝지어 제거하기 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ⭐️ 코드 import java.util.ArrayDeque; class Solution { public int solution(String s) { char[] c = s.toCharArray(); ArrayDeque stack = new ArrayDeque(); for(int i = 0; i < c.length; i++) { if (stack.isEmpty()) { stack.addLast(c[i]); } else { if (stack.peekLast() == c[i]) { stack.po..

728x90
반응형
LIST