행렬
-
행렬_LeetCode_200. Number of island swift알고리즘/알고리즘 문제풀이 2022. 2. 28. 17:34
https://leetcode.com/problems/number-of-islands/ 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 접근 방법 stack에 "1"인 좌표를 모두 저장, grid의 크기와 같은 방문여부Matrix init stack의 마지막 요소를 가져와, 4방의 좌표를 확인, "1"인 경우 재귀탐색 및 방문여부Matrix에 해당 좌표 true 1, 2 를 마쳤을 때, 섬의 갯수 += 1 stack의 다음 요소..
-
행렬_Leetcode_130.Surrounded Region Swift알고리즘/알고리즘 문제풀이 2022. 1. 25. 15:58
https://leetcode.com/problems/surrounded-regions/ 문제 접근 "O"를 queue에 추가 큐의 좌표값이 "Y"인지 확인. (추후 로직에서 방문했던 좌표는 Y로 변환하기 때문) searchGroup수행 -> 방문한 좌표를 "Y"로 바꾸고, Set형태로 인접한"O"의 좌표Collection을 반환 반환된 좌표 collection의 각 좌표에 대하여, boardEdge인지 검사 ( 해당 문제에서 뒤집히는 경우는 4면이 X인 경우인데, boardEdge에 있는 좌표는 한 면이 X가 아니므로 뒤집히지 않는다, 이는 여러개가 묶인 경우에도 동일) boardEdge와 무관할 경우, 해당 그룹의 좌표들을 전부 X로 변환 boardEdge에 있는 경우, undoList에 추가하여, ..
-
행렬_백준_1012알고리즘/알고리즘 문제풀이 2022. 1. 25. 14:34
https://www.acmicpc.net/problem/1012 OOP스럽게 짜 보았다.. 정답 더보기 import Foundation class Baek1012 { var matrix: [[Int]] var warm = 0 let rowLimit: Int let columnLimit: Int init(row: Int, column: Int) { matrix = [[Int]].init(repeating: [Int].init(repeating: 0, count: row), count: column) self.rowLimit = column self.columnLimit = row } func cabbage(_ row: Int, _ column: Int) { matrix[column][row] = 1 } ..
-
행렬_LeetCode_542 01matrix알고리즘/알고리즘 문제풀이 2022. 1. 24. 17:03
https://leetcode.com/problems/01-matrix/ 오답 testCase 49/50에서 막힌다. 정말 획기적인 방법을 사용하지 않는이상 통과가 힘든듯 ㅠㅠㅠ 더보기 더보기 func updateMatrix(_ mat: [[Int]]) -> [[Int]] { var sol = [[Int]].init(repeating: [Int].init(repeating: -1, count: mat[0].count), count: mat.count) var queue = [[Int]]() let emptyRow = [Bool].init(repeating: false, count: mat[0].count) var visited = [[Bool]].init(repeating: emptyRow, count:..