From 69260c71ff9915c848352304d4699dd464458c22 Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Thu, 9 Apr 2026 13:29:26 +0900 Subject: [PATCH 1/3] Create liv.swift --- .../liv.swift" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "WEEK10/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\202\260\353\252\250\354\226\221\355\203\200\354\235\274\353\247\201/liv.swift" diff --git "a/WEEK10/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\202\260\353\252\250\354\226\221\355\203\200\354\235\274\353\247\201/liv.swift" "b/WEEK10/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\202\260\353\252\250\354\226\221\355\203\200\354\235\274\353\247\201/liv.swift" new file mode 100644 index 0000000..1ad3b32 --- /dev/null +++ "b/WEEK10/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\354\202\260\353\252\250\354\226\221\355\203\200\354\235\274\353\247\201/liv.swift" @@ -0,0 +1,19 @@ +// 프로그래머스 - 산 모양 타일링 + +import Foundation + +func solution(_ n: Int, _ tops: [Int]) -> Int { + var dp1 = [Int](repeating: 0, count: n+1) + var dp2 = [Int](repeating: 1, count: n+1) + + for index in 1...n { + dp1[index] = (dp1[index - 1] + dp2[index - 1]) % 10007 + if tops[index - 1] == 1 { + dp2[index] = (dp1[index - 1] * 2 + dp2[index - 1] * 3) % 10007 + } + else { + dp2[index] = (dp1[index - 1] + dp2[index - 1] * 2) % 10007 + } + } + return (dp1[n] + dp2[n]) % 10007 +} From 51742dd11bfc0295049498a5a8614a1a88d4e088 Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Thu, 9 Apr 2026 13:30:20 +0900 Subject: [PATCH 2/3] Create liv.swift --- .../liv.swift" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "WEEK10/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\352\260\200\354\236\245\353\247\216\354\235\264\353\260\233\354\235\200\354\204\240\353\254\274/liv.swift" diff --git "a/WEEK10/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\352\260\200\354\236\245\353\247\216\354\235\264\353\260\233\354\235\200\354\204\240\353\254\274/liv.swift" "b/WEEK10/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\352\260\200\354\236\245\353\247\216\354\235\264\353\260\233\354\235\200\354\204\240\353\254\274/liv.swift" new file mode 100644 index 0000000..07fb2f7 --- /dev/null +++ "b/WEEK10/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\352\260\200\354\236\245\353\247\216\354\235\264\353\260\233\354\235\200\354\204\240\353\254\274/liv.swift" @@ -0,0 +1,42 @@ +// 프로그래머스 - 가장 많이 받은 선물 + +import Foundation + +func solution(_ friends: [String], _ gifts: [String]) -> Int { + var giftScore = [Int](repeating: 0, count: friends.count) + var history = [[String: Int]](repeating: [:], count: friends.count) + var next = [Int](repeating: 0, count: friends.count) + + for gift in gifts { + let line = gift.split(separator: " ").map { String($0) } + let sender = friends.firstIndex(of: line[0])! + let receiver = friends.firstIndex(of: line[1])! + + giftScore[sender] += 1 + giftScore[receiver] -= 1 + + history[sender][line[1], default: 0] += 1 + } + + for (index, name) in friends.enumerated() { + var friend = index + 1 + while friend < friends.count { + let friendName = friends[friend] + let fromMe = history[index][friendName] ?? 0 + let fromFriend = history[friend][name] ?? 0 + + if fromMe > fromFriend { next[index] += 1 } + else if fromMe < fromFriend { next[friend] += 1 } + else { + let myScore = giftScore[index] + let friendScore = giftScore[friend] + if myScore > friendScore { next[index] += 1 } + else if myScore < friendScore { next[friend] += 1 } + } + + friend += 1 + } + } + + return next.max() ?? 0 +} From fcffa212e4a148d9d1e0503522f83d477abbd84a Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Thu, 9 Apr 2026 13:32:37 +0900 Subject: [PATCH 3/3] Create liv.swift --- .../liv.swift" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 "WEEK10/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\217\204\353\204\233\352\263\274\353\247\211\353\214\200\352\267\270\353\236\230\355\224\204/liv.swift" diff --git "a/WEEK10/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\217\204\353\204\233\352\263\274\353\247\211\353\214\200\352\267\270\353\236\230\355\224\204/liv.swift" "b/WEEK10/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\217\204\353\204\233\352\263\274\353\247\211\353\214\200\352\267\270\353\236\230\355\224\204/liv.swift" new file mode 100644 index 0000000..ab98a6d --- /dev/null +++ "b/WEEK10/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\217\204\353\204\233\352\263\274\353\247\211\353\214\200\352\267\270\353\236\230\355\224\204/liv.swift" @@ -0,0 +1,46 @@ +// 프로그래머스 - 도넛과 막대 그래프 + +import Foundation + +func solution(_ edges: [[Int]]) -> [Int] { + var donut = 0; var stick = 0; var eight = 0 + var answer = 0 + + var count = 0 + edges.forEach { count = max(count, max($0[0], $0[1])) } + + var inTable = [Int](repeating: 0, count: count + 1) + var outTable = [Set](repeating: [], count: count + 1) + edges.forEach { edge in + outTable[edge[0]].insert(edge[1]) + inTable[edge[1]] += 1 + } + + var startItems = Set() + for (number, targets) in outTable.enumerated() + where targets.count >= 2 && inTable[number] == 0 { + answer = number + startItems = outTable[answer] + break + } + + for item in startItems { + var visited = Set() + var current = item + + while true { + if visited.contains(current) { donut += 1; break } + + let nextItems = outTable[current] + visited.insert(current) + + if nextItems.isEmpty { stick += 1; break } + + if nextItems.count == 2 { eight += 1; break } + + current = nextItems.first! + } + } + + return [answer, donut, stick, eight] +}