알고리즘/Lv1. 프로그래머스 15

[프로그래머스] 가장 많이 받은 선물 -JAVA

https://school.programmers.co.kr/learn/courses/30/lessons/258712 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 1레벨짜리 문제가 벌써 풀기 싫어진다.매번 프로그래머스에서 풀때마다 느끼지만 1~2레벨 구분은 별 의미도 없는것 같다..우선 처음 고려해야 할 것은 서로 주고받은 선물의 개수이다.두 번째는 선물지수이다. 이름을 키로 갖고 값을 선물 지수로 갖는 map,서로 선물을 주고받은 데이터를 저장하는 map 두개가 필요하다. 서로 주고받은 선물 개수가 같은 것과 둘다 주고받지 않은것은 같다고 볼 수 있다. i..

같은숫자는싫어

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

체육복

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

공원 산책

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

개인정보 수집 유효기간

출처 : https://school.programmers.co.kr/learn/courses/30/lessons/150370 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; class Solution { public List solution(String today, String[] terms, String[] privacies) { List answer=new ArrayList(); String [] todayArr=today.split("\\."); String year=todayArr[0]; String month=t..

2016년

출처 : https://school.programmers.co.kr/learn/courses/30/lessons/12901 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { public String solution(int a, int b) { String answer = ""; String [] day={"FRI","SAT","SUN","MON","TUE","WED","THU"}; int [] dateArr={31,29,31,30,31,30,31,31,30,31,30,31}; int date=0; for(int i=0;i

콜라 문제

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

가장 가까운 같은 글자

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

푸드 파이트 대회

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

두 개 뽑아서 더하기

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