Algorithm/LeetCode14 [LeetCode] 200. Number of Islands (swift) Number of Islands - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이 2차원 배열에 대해서 for문을 돌면서 맵이 "1"이고 아직 방문하지 않은 곳 이면 dfs를 돌아준다. [row][column]으로 이루어진 visited 배열을 만들어서 dfs를 돌 때 "1"인 곳에 방문이 되었으면 visited를 true로 체크한다. 한 번의 dfs 탐색을 하는 경우의 수가 섬의 개수를 의미한다. 코드 class Solution { func numIsla.. 2021. 10. 13. [LeetCode] 797. All Paths From Source to Target (swift) All Paths From Source to Target - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이 0번 부터 시작하여 n-1번까지 가는 경로를 모두 찾으면 되는 문제다. 입력 받은 graph에서 0번 꼭짓점과 연결된 꼭짓점부터 dfs를 탐색하도록 했다. // 0번 부터 탐색 시작 for vertex in graph[0] { dfs(vertex, [0, vertex], graph) } 비슷한 방식으로 dfs 함수 내에서 vertex와 연결된 꼭짓점으.. 2021. 10. 13. 이전 1 2 3 다음