목록Algorithm/Programmers (76)
S E P H ' S
프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 풀이 조건에 맞게 조이스틱 조작 횟수의 최솟값을 구하는 문제였다. 조작 횟수의 최소값은 두가지로 나누어서 구하는 것이 핵심이다. 1. 알파벳 선택하기 A 에서 주어진 알파벳까지 조작하는데 A ~ 주어진 알파벳 의 값과 주어진 알파벳 ~ Z + 1 (A에서 반대로 조작하는 것도 있으므로 주어진 알파벳에서 Z 까지의 값과 A를 포함한 +1 까지 해준다.) 중 최소를 선택한다. 2. 커서 이동횟수 구하기 가장 헤맸던 부분이다. 처음엔 while문을 통해서 idx가 가리키는 값 기준으로 왼쪽, 오른쪽 값을 확인..
프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 풀이 정말 쉬운 문제지만 조건 확인에 덜렁이는 나같은 사람에게는 좋은 문제였다. prices의 모든 값을 큐에 넣은 후 큐의 값이 없을때까지 반복하면서 현재 값이 prices의 다음 값들과 비교해가면서 작아질때 까지 카운트를 1씩 늘려가면 되는 문제이다. 빼먹었던 조건은 현재 값보다 다음 값이 작아졌을 때 카운트를 1을 증가시키고 break를 해주어야 한다. 몇 초뒤에 가격이 떨어졌는지를 정답으로 요구하고 있기 때문에 작아진 다음에 1초를 더해야 했고 break를 하지 않으면 계속해서 다음 값을 비교하면..
프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 풀이 문제를 보자마자 조합이구나가 떠오른게 많이 발전한 것 같다. 조금 어려웠던 점은 data에 주어지는 조건에 맞도록 어떻게 조합을 맞춰나가야 하는지가 잘 떠오르지 않았다. 그래서 가능한 조합을 모두 만든 다음, 그 조합이 data에 주어지는 조건에 부합하는지 확인하도록 했다. 또한 조건에 부합하는 조합이 없다면 0을 출력해야한다. answer를 0으로 초기화 해두고 모든 조건을 확인하고도 answer의 증가가 일어나지 않으면 조건에 맞는 것이 없는 것이다. 그대로 코드를 작성해서 통과할 수 있었다. ..
프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 풀이 처음엔 단순히 dfs를 생각했다가 경우의 수가 많아질 수 있다와 1칸, 2칸 ~ N칸 늘어나게 되더라도 몇 칸마다 채워주는 규칙은 똑같지 않나? 라는 생각에 DP가 떠올랐다. 점화식 구하는 것은 DP 문제 중에 기초 중에 기초였지만 경우의 수를 1,000,000,007로 나누는 것을 DP 배열에 저장할 때 모두 해줘야 했다. 앞으로 저런 제한사항이 있다면 주의해서 과정에 꼭 넣는 것을 빼먹지 말아야겠다. public class 타일링_2xn { public int solution(int n) { i..