알고리즘 48

[프로그래머스] 올바른 괄호 -java

출처 : https://school.programmers.co.kr/learn/courses/30/lessons/12909 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { boolean solution(String s) { boolean answer = true; int cnt1=0; int cnt2=0; for(int i=0;icnt1)return false; //마지막까지 갔을 때 '('와 ')'의 개수가 다르면 false if(i==s.length()-1&&cnt2!=cnt1)return false; } return an..

[프로그래머스] 의상 -java

출처 : https://school.programmers.co.kr/learn/courses/30/lessons/42578#qna 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; class Solution { public int solution(String[][] clothes) { int answer = 0; //종류와 옷의 개수를 담을 map Map map=new HashMap(); for(int i=0;i

[프로그래머스] 프렌즈4블록 -java

출처 : https://school.programmers.co.kr/learn/courses/30/lessons/17679 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; class Solution { public int solution(int m, int n, String[] board) { int answer = 0; //블록이 제거되면 떨어져서 재정리 할 큐 Queue q=new LinkedList(); String arr[][]=new String[m][n]; String newArr[][]=new String[m..

[프로그래머스] [3차] 파일명 정렬 - java

출처 : https://school.programmers.co.kr/learn/courses/30/lessons/17686# 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; class Solution { public String[] solution(String[] files) { String[] answer = new String[files.length]; //헤드 숫자 꼬리 나눌 배열 String split[][]= new String[files.length][3]; for(int i=0;i

[프로그래머스] 스킬트리 - java

출처 : https://school.programmers.co.kr/learn/courses/30/lessons/49993 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; class Solution { public int solution(String skill, String[] skill_trees) { int answer = 0; String ABC[]={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T" ,"U","V","W",..

[프로그래머스] 주식가격 - java

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

[프로그래머스] [3차] n진수 게임 - java

출처 : https://school.programmers.co.kr/learn/courses/30/lessons/17687 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; class Solution { public String solution(int n, int t, int m, int p) { String answer=""; StringBuilder builder = new StringBuilder(); for(int i=0;i(i라는 숫자를 n진수로 변환)append하였고 1번부터 체크하기 때문에 쉽게 앞에 공백을 하..

[프로그래머스] 오픈채팅방 - java

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

[프로그래머스] 주차 요금 계산 - java

출처 : https://school.programmers.co.kr/learn/courses/30/lessons/92341 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; class Solution { public int[] solution(int[] fees, String[] records) { int[] answer = {}; //timeMap은 현재 들어오는 차량 혹은 나가는 차량의 번호와 시간 //resultMap은 차량이 나갈때마다 계산해서 저장 Map timeMap=new HashMap(); Map result..