- 오늘의 계획
- 실리콘밸리 인턴쉽 리액트 css 작업하기
- 프로그래머스/백준 사이트에서 알고리즘 문제 풀이(DFS, BFS)
- 실리콘밸리 인턴쉽 리액트 css 작업하기
-
오늘의 회고
- react 작업
- backend와의 연결 및 페이지 구현은 완료하였고, 아직 하지 못한 css 작업을 하였다.
- flex를 활용하여 div를 정렬하는데 용이함을 알게 되었다.
-
DFS, BFS 문제 풀이 : 단어 변환(프로그래머스 LEVEL 3)
- 깊이(depth)를 우선으로 탐색하는 dfs를 통해 문제를 해결하였다.
- begin으로부터 시작한 temp 값이 target과 일치한다면 depth와 answer 중 더 작은 값을 반환하도록 탈출 조건을 정의해주고, words 배열 속 word와 temp가 한 글자만 다른 경우의 word를 다음에 시작할 nextBegin 배열에 삽입하였다.
- 그 후 얕은 복사를 통해 words를 새 배열 newWords에 복사하여 temp 값을 제거한다. (newWords 속에 tmep가 있을 경우 즉, nextBegin에 추가된 경우)
- 마지막으로 dfs를 반복함으로 answer 값을 줄여가며 문제를 해결하였다.
-
코드 :
```python from copy import copy def solution(begin, target, words): answer = 0 depth = 0 if target not in words: return answer maxAnswer = len(words) def dfs(temp, words, answer, depth): if temp == target: if answer > depth: answer = depth return answer nextBegin = [] for word in words: difference = 0 for i in range(len(word)): if word[i] != temp[i]: difference += 1 if difference == 1: nextBegin.append(word) newWords = copy(words) if temp in newWords: newWords.remove(temp) depth += 1 for b in nextBegin: answer = dfs(b, newWords, answer, depth) return answer answer = dfs(begin, words, maxAnswer, depth) return answer ```
- react 작업