분류 전체보기
-
import Foundation func solution(_ word:String) -> Int { var answer = 0 var cases = [781, 156, 31, 6, 1] let words = word.map { char -> Int in switch char { case "A": return 0 case "E": return 1 case "I": return 2 case "O": return 3 default: return 4 } } for word in words { answer += cases.removeFirst() * word + 1 } return answer }
[Swift] 모음사전import Foundation func solution(_ word:String) -> Int { var answer = 0 var cases = [781, 156, 31, 6, 1] let words = word.map { char -> Int in switch char { case "A": return 0 case "E": return 1 case "I": return 2 case "O": return 3 default: return 4 } } for word in words { answer += cases.removeFirst() * word + 1 } return answer }
2023.04.29 -
import Foundation func solution(_ arr:[[Int]]) -> [Int] { var zeroCount = 0 var oneCount = 0 func quadCompression(_ row: Int, _ col: Int, _ n: Int) { let target = arr[row][col] for i in row..
[Swift] 쿼드압축 후 개수세기import Foundation func solution(_ arr:[[Int]]) -> [Int] { var zeroCount = 0 var oneCount = 0 func quadCompression(_ row: Int, _ col: Int, _ n: Int) { let target = arr[row][col] for i in row..
2023.04.29 -
import Foundation func solution(_ skill:String, _ skill_trees:[String]) -> Int { func available(_ skill: String, _ tree: String) -> Bool { let alza = tree.filter { skill.contains($0) } return skill.starts(with: alza) } return skill_trees.map { available(skill, $0) }.filter { $0 }.count }
[Swift] 스킬트리import Foundation func solution(_ skill:String, _ skill_trees:[String]) -> Int { func available(_ skill: String, _ tree: String) -> Bool { let alza = tree.filter { skill.contains($0) } return skill.starts(with: alza) } return skill_trees.map { available(skill, $0) }.filter { $0 }.count }
2023.04.27 -
import Foundation func solution(_ dirs:String) -> Int { var x = 0 var y = 0 var result: Set = [] for dir in dirs { switch dir { case "U": if 5 < y + 1 { continue } result.insert("\(x)\(y)UD") y += 1 case "L": if x - 1 < -5 { continue } x -= 1 result.insert("\(x)\(y)LR") case "R": if 5 < x + 1 { continue } result.insert("\(x)\(y)LR") x += 1 default: if y - 1 < -5 { continue } y -= 1 result.insert..
[Swift] 방문길이import Foundation func solution(_ dirs:String) -> Int { var x = 0 var y = 0 var result: Set = [] for dir in dirs { switch dir { case "U": if 5 < y + 1 { continue } result.insert("\(x)\(y)UD") y += 1 case "L": if x - 1 < -5 { continue } x -= 1 result.insert("\(x)\(y)LR") case "R": if 5 < x + 1 { continue } result.insert("\(x)\(y)LR") x += 1 default: if y - 1 < -5 { continue } y -= 1 result.insert..
2023.04.27 -
import Foundation func solution(_ land:[[Int]]) -> Int{ var land = land for i in 0..
[Swift] 땅따먹기import Foundation func solution(_ land:[[Int]]) -> Int{ var land = land for i in 0..
2023.04.27 -
import Foundation func solution(_ record:[String]) -> [String] { var result: [String] = [] var nickName: [String : String] = [:] let record = record.map { $0.components(separatedBy: " ") } record.forEach { if $0[0] == "Enter" || $0[0] == "Change" { nickName[$0[1]] = $0[2] } } record.forEach { if $0[0] == "Enter" { result.append("\(nickName[$0[1]]!)님이 들어왔습니다.") } if $0[0] == "Leave" { result.appe..
[Swift] 오픈채팅방import Foundation func solution(_ record:[String]) -> [String] { var result: [String] = [] var nickName: [String : String] = [:] let record = record.map { $0.components(separatedBy: " ") } record.forEach { if $0[0] == "Enter" || $0[0] == "Change" { nickName[$0[1]] = $0[2] } } record.forEach { if $0[0] == "Enter" { result.append("\(nickName[$0[1]]!)님이 들어왔습니다.") } if $0[0] == "Leave" { result.appe..
2023.04.27 -
import Foundation func solution(_ k:Int, _ dungeons:[[Int]]) -> Int { var result = 0 var visited: [Bool] = Array(repeating: false, count: dungeons.count) func dfs(_ index: Int, _ tired: Int, _ depth: Int) { var tired = tired visited[index] = true tired -= dungeons[index][1] for i in 0..
[Swift] 피로도import Foundation func solution(_ k:Int, _ dungeons:[[Int]]) -> Int { var result = 0 var visited: [Bool] = Array(repeating: false, count: dungeons.count) func dfs(_ index: Int, _ tired: Int, _ depth: Int) { var tired = tired visited[index] = true tired -= dungeons[index][1] for i in 0..
2023.04.27 -
import Foundation func solution(_ n:Int, _ t:Int, _ m:Int, _ p:Int) -> String { var number = 0 var result = "" var queue: [String] = [] while queue.count < m * t { String(number, radix: n).forEach { queue.append(String($0)) } number += 1 } for i in 0..
[Swift] [3차] N진수 게임import Foundation func solution(_ n:Int, _ t:Int, _ m:Int, _ p:Int) -> String { var number = 0 var result = "" var queue: [String] = [] while queue.count < m * t { String(number, radix: n).forEach { queue.append(String($0)) } number += 1 } for i in 0..
2023.04.27