코딩테스트-알고리즘/프로그래머스 20

[프로그래머스/Lv.1] 푸드 파이트 대회

https://school.programmers.co.kr/learn/courses/30/lessons/134240?language=java 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { public String solution(int[] food) { String answer = ""; for (int i = 0; i < food.length; i++) { food[i] = food[i] / 2; } for (int i = 1; i < food.length; i++) { int index = 0; while (index <..

[프로그래머스/Lv.2] 주차 요금 계산

https://school.programmers.co.kr/learn/courses/30/lessons/92341 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr HashMap을 사용하는 방법도 생각했으나 약간 다르게 풀어보았다 1. Set set = new HashSet(); // 차량 번호 중복 제거 for(int i = 0 ; i < records.length; i++) { String[] str = records[i].split(" "); set.add(str[1]); } List car = new ArrayList(set); // 차량 번호 리스트..

[프로그래머스/Lv.2] 스킬트리

https://school.programmers.co.kr/learn/courses/30/lessons/49993# 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 스킬이 "CBD"라면 스킬트리에 서로 붙어있든 떨어져있든 **C**B**D** 순으로 있어야한다 그리고 전부가 나오지는 않아도되나 B는 앞에 C가 없으면 나올 수 없고 D는 앞에 B 그리고 C가 없다면 나올 수 없다 스킬트리 배열을 돌며 조건에 만족하면 count를 더해주는데 우선 스킬 글자 그대로 포함되어있다면 나눠서 따져볼 필요가 없어서 바로 count를 더해주었고 아니라면 check함수로 ..

[프로그래머스/Lv.2] 땅따먹기

https://school.programmers.co.kr/learn/courses/30/lessons/12913# 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 처음 접근할 때는 너무 단순하게 생각했었다 import java.util.*; class Solution { static boolean[] check = new boolean[4]; static int answer; static int max; int solution(int[][] land) { game(0, land); return answer; } void game(int x, int[][]..

[프로그래머스/Lv.0] 안전지대

https://school.programmers.co.kr/learn/courses/30/lessons/120866 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { int[] dx = {-1, -1, 0, 1, 1, 1, 0, -1}; int[] dy = {0, 1, 1, 1, 0, -1, -1, -1}; boolean[][] visited; public int solution(int[][] board) { int answer = 0; visited = new boolean[board.length][board[0].length..

[프로그래머스/Lv.2] [PCCP 기출문제] 2번 / 석유 시추 -2

시간초과를 해결하고 너무너무너무 기뻐서 새로 글을 쓴다 아직 하나 남았지만,, https://school.programmers.co.kr/learn/courses/30/lessons/250136#qna 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; class Solution { static int[] dx = {0, 0, -1, 1}; static int[] dy = {-1, 1, 0, 0}; static int result; static int[] resultArray; static HashSet set = new H..

[프로그래머스/Lv.2] [PCCP 기출문제] 2번 / 석유 시추

https://school.programmers.co.kr/learn/courses/30/lessons/250136 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 첫번째 생각 class Solution { static int[] dx = {0, 0, -1, 1}; static int[] dy = {-1, 1, 0, 0}; static int result; static int[] resultArray; static int oil = 1; public int solution(int[][] land) { int answer = 0; resultArray = n..

[프로그래머스/Lv.2] 뒤에 있는 큰 수 찾기

https://school.programmers.co.kr/learn/courses/30/lessons/154539 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; import java.util.stream.Collectors; class Solution { public int[] solution(int[] numbers) { int[] answer = new int[numbers.length]; answer[answer.length-1] = -1; // stream 사용해서 List로 바꾸기 List numbersLis..

[프로그래머스/Lv.1] 가장 많이 받은 선물

https://school.programmers.co.kr/learn/courses/30/lessons/258712 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 결과내기까지 굉장히 복잡한거같아서 중간중간 남기고 출력확인하면서 풀었다 아래는 그 과정 1. 선물 주고받은거 map에 넣기 for(int i=0; i [i] 횟수 담아줄 수 for(int i=0; i giftNum.get(friends[j])) result[i] += 1; else if (giftNum.get(friends[i]) < giftNum.get(friends[j])) result[j]..

[프로그래머스/Lv.2] 짝지어 제거하기

https://school.programmers.co.kr/learn/courses/30/lessons/12973 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; class Solution { public int solution(String s) { int answer = 0; Stack stack = new Stack(); for(int i=0; i