분류 전체보기
-
import Foundation func checkDistance(_ places: [String]) -> Int { let place: [[String]] = places.map { $0.map { String($0) } } var points: [(i: Int, j: Int)] = [] // 좌표 저장 for i in 0..
[Swift] 거리두기 확인하기import Foundation func checkDistance(_ places: [String]) -> Int { let place: [[String]] = places.map { $0.map { String($0) } } var points: [(i: Int, j: Int)] = [] // 좌표 저장 for i in 0..
2023.06.17 -
import Foundation func solution(_ k:Int, _ d:Int) -> Int64 { var result: Int64 = 0 for x in stride(from: 0, through: d, by: k) { result += Int64(floor(sqrt(Double((d*d) - (x*x))) / Double(k))) + 1 } return result }
[Swift] 점 찍기import Foundation func solution(_ k:Int, _ d:Int) -> Int64 { var result: Int64 = 0 for x in stride(from: 0, through: d, by: k) { result += Int64(floor(sqrt(Double((d*d) - (x*x))) / Double(k))) + 1 } return result }
2023.06.17 -
import Foundation func solution(_ board: [[Int]]) -> Int { var dp: [[Int]] = Array(repeating: Array(repeating: 0, count: board[0].count + 1), count: board.count + 1) var globalMax = 0 for i in 1...board.count { for j in 1...board[0].count { if board[i-1][j-1] == 1 { dp[i][j] = min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]) + 1 if dp[i][j] > globalMax { globalMax = dp[i][j] } } } } return globalMax * ..
[Swift] 가장 큰 정사각형 찾기import Foundation func solution(_ board: [[Int]]) -> Int { var dp: [[Int]] = Array(repeating: Array(repeating: 0, count: board[0].count + 1), count: board.count + 1) var globalMax = 0 for i in 1...board.count { for j in 1...board[0].count { if board[i-1][j-1] == 1 { dp[i][j] = min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]) + 1 if dp[i][j] > globalMax { globalMax = dp[i][j] } } } } return globalMax * ..
2023.06.17 -
import Foundation struct MaxHeap { var heap: Array = [] var isEmpty: Bool { return heap.count Bool { if insertIndex heap[parentIndex] ? true : false } var insertIndex: Int = heap.count - 1 while isMoveUp(insertIndex) { let parentIndex: Int = insertIndex / 2 heap.swapAt(insertIndex, parentIndex) insertIndex = parentIndex } } enum moveDownStatus { case left, right, none } mutating func pop() -> T?..
[Swift] 배달import Foundation struct MaxHeap { var heap: Array = [] var isEmpty: Bool { return heap.count Bool { if insertIndex heap[parentIndex] ? true : false } var insertIndex: Int = heap.count - 1 while isMoveUp(insertIndex) { let parentIndex: Int = insertIndex / 2 heap.swapAt(insertIndex, parentIndex) insertIndex = parentIndex } } enum moveDownStatus { case left, right, none } mutating func pop() -> T?..
2023.06.17 -
import Foundation func solution(_ rows:Int, _ columns:Int, _ queries:[[Int]]) -> [Int] { // rows * columns 생셩 var array: [[Int]] = [] var result: [Int] = [] for i in 0..
[Swift] 행렬 테두리 회전하기import Foundation func solution(_ rows:Int, _ columns:Int, _ queries:[[Int]]) -> [Int] { // rows * columns 생셩 var array: [[Int]] = [] var result: [Int] = [] for i in 0..
2023.06.17 -
import Foundation // 방법 1 func calculate(_ num: [Int64], _ expression: [String], _ priority: [String]) -> Int64 { var num = num var tmp:[Int64] = [] var expression = expression for i in 0.. Int64 { switch self { case .multiple: return n1 * n2 case .plus: return n1 + n2 case .minus: return n1 - n2 } } } func operate(numbers: [Int64], opers: [Character], prior: [Operation]) -> Int64 { var numbers ..
[Swift] 수식 최대화import Foundation // 방법 1 func calculate(_ num: [Int64], _ expression: [String], _ priority: [String]) -> Int64 { var num = num var tmp:[Int64] = [] var expression = expression for i in 0.. Int64 { switch self { case .multiple: return n1 * n2 case .plus: return n1 + n2 case .minus: return n1 - n2 } } } func operate(numbers: [Int64], opers: [Character], prior: [Operation]) -> Int64 { var numbers ..
2023.06.17 -
import Foundation func solution(_ maps:[String]) -> [Int] { // (x+1, y), (x-1, y), (x, y+1), (x, y-1) let dx = [1, -1, 0, 0] let dy = [0, 0, 1, -1] // 2차원 배열로 변형 let maps: [[String]] = maps.map { $0.map { String($0) } } // row * col let row = maps.count let col = maps[0].count var answers: [Int] = [] var visited: [[Bool]] = Array(repeating: Array(repeating: false, count: col), count: row) func b..
[Swift] 무인도 여행import Foundation func solution(_ maps:[String]) -> [Int] { // (x+1, y), (x-1, y), (x, y+1), (x, y-1) let dx = [1, -1, 0, 0] let dy = [0, 0, 1, -1] // 2차원 배열로 변형 let maps: [[String]] = maps.map { $0.map { String($0) } } // row * col let row = maps.count let col = maps[0].count var answers: [Int] = [] var visited: [[Bool]] = Array(repeating: Array(repeating: false, count: col), count: row) func b..
2023.06.17 -
import Foundation func solution(_ p:String) -> String { // 입력이 빈 문자열인 경우, 빈 문자열 반환 if p.count < 1 {return ""} var count = 0, index = p.startIndex // repeat while문으로 균형잡힌 괄호 문자열인지 확인 // ( 이면 count + 1, ) 이면 count - 1 // count가 0이 될 때까지 진행 repeat{ count += String(p[index]) == "(" ? 1 : -1 index = p.index(after: index) } while count != 0 // 위의 과정에서 알아낸 index 값을 토대로 u, v 문자열 나누기 var u = String(p[..
[Swift] 괄호 변환import Foundation func solution(_ p:String) -> String { // 입력이 빈 문자열인 경우, 빈 문자열 반환 if p.count < 1 {return ""} var count = 0, index = p.startIndex // repeat while문으로 균형잡힌 괄호 문자열인지 확인 // ( 이면 count + 1, ) 이면 count - 1 // count가 0이 될 때까지 진행 repeat{ count += String(p[index]) == "(" ? 1 : -1 index = p.index(after: index) } while count != 0 // 위의 과정에서 알아낸 index 값을 토대로 u, v 문자열 나누기 var u = String(p[..
2023.06.17