Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🌱WIL
🚀주간 목표 문제 수: 3개
프로그래머스 #43165. 타겟 넘버(java): 그래프 / Level 2
정리한 링크: (바로가기)
🚩플로우 (선택)
count를 0으로 초기화한다.backtracking()함수에서는solution()함수에서는backtracking(0, 0)을 호출하여 탐색을 시작한다.count를 반환한다.🚩제출한 코드
💡TIL
왜냐하면 curr_sum은 음수도 될 수 있고, target도 0보다 클 수도 작을 수도 있기 때문
이다. 즉,
curr_sum > target이라는 조건은 유효하지 않았기 때문이다.경우에 따라 뒤에서 -가 계속 붙으면 결국 target을 맞출 수도 있기 때문이다.
백준 #15683. 감시 - 백트래킹: 구현 / 골드3
정리한 링크: (바로가기)
🚩플로우 (선택)
office: 사무실 상태 입력받기cctvs: CCTV 위치와 번호 저장directions: 상, 우, 하, 좌 방향 정의cctv_dirs: 각 CCTV 번호별 가능한 방향 세트 정의count_zero(): 감시받지 못한 칸(0) 개수 세기watch(): 특정 방향으로 감시 수행dfs():🚩제출한 코드
💡TIL
copy()를 썼다. 하지만copy()는 얕은 복사 함수이기 때문에 깊은 복사가 되지 않고, 동일한 주소값을 가진다. 따라서 꼭 깊은 복사할 때에는copy.deepcopy()를 사용하도록 하자.iterable연산이 되지 않는다. 리스트는 for loop를 돌 때 인자가 하나만 있어도 돌아가지만, 튜플은 오류가 발생한다. 이러한 이유 때문에cctv_dirs에서도 튜플이 아닌 리스트로 변경했다.프로그래머스 #1844. 게임 맵 최단거리(java): 그래프 / Level 2
정리한 링크: (바로가기)
🚩플로우 (선택)
visited[n][m]: 방문 여부 체크 배열queue: BFS 탐색용 큐dirs: 상하좌우 이동을 위한 방향 벡터(nx, ny)를 계산maps[n-1][m-1]반환1반환🚩제출한 코드
💡TIL
자바로 풀이하는 과정이 파이썬에 비해 까다로웠다. 배열 선언이나 출력 방식에 있어서 익숙하지 않아서 시행착오가 있었다.
자바에서 2차원 배열을 출력하려고
System.out.println(dirs.toString());를 쓰면, 배열의 메모리 주소만 출력된다. 배열 내용을 보기 위해서는Arrays.deepToString()을 사용해야 한다.또한 자바에서 좌표를 관리할 때
Point클래스를 활용할 수 있다는 점도 배우게 되었다.다만 문제 풀이에서는 별도의 클래스를 만들지 않고 int[] 배열로 처리하였다.
백준 #16987. 란으로 계란치기 - 백트래킹: 구현 / 골드5
정리한 링크: (바로가기)
🚩플로우 (선택)
if i == cur_idx or eggs[i][0] <= 0)eggs[cur_idx])과 순회 중인 계란(eggs[i])을 서로 타격시킨다.eggs[cur_idx])과 순회 중인 계란(eggs[i])의 상태를 원래대로 되돌린다.max_broken값을 출력한다.🚩제출한 코드
💡TIL
이를 해결하기 위해
broken이라는 불리언 변수를 두고, 실제로 한 번이라도 계란을 쳤는지를 체크했다. 만약 한 번도 치지 못했다면 그 경우에도 다음 계란으로 넘어가야 한다는 점이 중요하다.처음에는 조건 설정을 잘못해서 예제 테스트 케이스를 통과하지 못했지만, 다른 사람의 풀이를 참고하면서 많이 배웠다.