๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
728x90
๋ฐ˜์‘ํ˜•

์นด์นด์˜ค16

[Swift] 2019 KAKAO BLIND RECRUITMENT ๋ธ”๋ก ๊ฒŒ์ž„ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋ธ”๋ก ๊ฒŒ์ž„ [[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,4,0,0,0],[0,0,0,0,0,4,4,0,0,0],[0,0,0,0,3,0,4,0,0,0],[0,0,0,2,3,0,0,0,5,5],[1,2,2,2,3,3,0,0,0,5],[1,1,1,0,0,0,0,0,0,5]] 2 programmers.co.kr Solution 1. ๋จผ์ € ๊ฒ€์€ ๋ธ”๋ก์„ ๋–จ์–ด๋œจ๋ ค ์‚ญ์ œ๊ฐ€ ๊ฐ€๋Šฅํ•œ ๋ธ”๋ก๋“ค์„ ์ฐพ์•„๋‚ธ๋‹ค. ์ฃผ์–ด์ง„ ๋ธ”๋ก์€ ์ฐจ๋ก€๋Œ€๋กœ 1๋ฒˆ ๋ธ”๋ก์˜ 0,1,2,3 ํƒ€์ž…, 2๋ฒˆ ๋ธ”๋ก์˜ 0,1,2,3 ํƒ€์ž… , 3๋ฒˆ ๋ธ”๋ก์˜ 0,1,2,3ํƒ€์ž…์ด ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•  ๋•Œ ๊ฒ€์€ ๋ธ”.. 2022. 3. 28.
[Swift] 2019 KAKAO WINTER INTERNSHIP ํ˜ธํ…” ๋ฐฉ ๋ฐฐ์ • Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ํ˜ธํ…” ๋ฐฉ ๋ฐฐ์ • programmers.co.kr Solution 1. ์—ฐ์†๋œ ๋ฐฉ๋“ค์˜ ์‹œ์ž‘๊ณผ ๊ธธ์ด๋ฅผ ์ €์žฅํ•ด ๋†“์„ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ ๋‹ค. ์ด ๋ฌธ์ œ์˜ ํ•ต์‹ฌ์€ ํˆฌ์ˆ™์„ ์›ํ•˜๋Š” ๋ฐฉ์ด ์ค‘๋ณต๋˜์—ˆ์„ ๋•Œ ํ•ด๋‹น ๋ฐฉ๋ณด๋‹ค ํฌ๋ฉด์„œ ๊ฐ€์žฅ ์ž‘์€ ๋ฐฉ์„ ์ฐพ๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ์—ฐ์†๋œ ๋ฐฉ์˜ ๊ธธ์ด์™€ ์‹œ์ž‘๋œ ๋ฐฉ์˜ ์œ„์น˜๋ฅผ ๋”ํ•ด์ฃผ๋ฉด ์‰ฝ๊ฒŒ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด 10๊ฐœ์˜ ๋ฐฉ ์ค‘ 2,3,4,5 ๊ฐ€ ์ด๋ฏธ ์ฐจ์žˆ๋‹ค๋ฉด ์‹œ์ž‘๋œ ๋ฐฉ์˜ ์œ„์น˜๋Š” 2์ด๊ณ  ์—ฐ์†๋œ ๋ฐฉ์˜ ๊ธธ์ด๋Š” 4์ž…๋‹ˆ๋‹ค. ๊ณ ๋กœ 2,3,4,5 ์ค‘์— ์ค‘๋ณต๋œ ๋ฐฉ์ด ์žˆ๋‹ค๋ฉด 2(์‹œ์ž‘๋œ ๋ฐฉ์˜ ์œ„์น˜) + 4(์—ฐ์†๋œ ๋ฐฉ์˜ ๊ธธ์ด) = 6์ด๋ฏ€๋กœ 6๋ฒˆ ๋ฐฉ์— ๋„ฃ์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. class Room { var root:Int64,length:Int64 init(root:Int64,length:Int.. 2022. 2. 20.
[Swift] 2022 KAKAO BLIND RECRUITMENT ์‚ฌ๋ผ์ง€๋Š” ๋ฐœํŒ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์‚ฌ๋ผ์ง€๋Š” ๋ฐœํŒ [[1, 1, 1], [1, 1, 1], [1, 1, 1]] [1, 0] [1, 2] 5 [[1, 1, 1], [1, 0, 1], [1, 1, 1]] [1, 0] [1, 2] 4 programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” ์™„์ „ ํƒ์ƒ‰์œผ๋กœ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. 1. ํ”Œ๋ ˆ์ด์–ด์˜ ์œ„์น˜์™€ ๊ฒŒ์ž„ ๋๋‚ฌ์„ ๋•Œ ์›€์ง์ธ ํšŸ์ˆ˜์™€ ์Šน์ž๋ฅผ ์•Œ๋ ค์ค„ ๊ตฌ์กฐ์ฒด๋ฅผ ๋งŒ๋“ ๋‹ค. struct Location { var x:Int,y:Int } struct GameResult { var count:Int,isWinnerA:Bool } 2. board์˜ ๊ฐ€์žฅ ์ž๋ฆฌ๋ฅผ 0์œผ๋กœ ๊ฐ์‹ธ์ค€๋‹ค. Index out of range ์˜ค๋ฅ˜๋ฅผ ์‰ฝ๊ฒŒ ํ”ผํ•˜๊ธฐ ์œ„ํ•ด์„œ ์ž…๋‹ˆ๋‹ค. func wrapBoard.. 2022. 1. 20.
[Swift] 2022 KAKAO BLIND RECRUITMENT ํŒŒ๊ดด๋˜์ง€ ์•Š์€ ๊ฑด๋ฌผ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ํŒŒ๊ดด๋˜์ง€ ์•Š์€ ๊ฑด๋ฌผ [[5,5,5,5,5],[5,5,5,5,5],[5,5,5,5,5],[5,5,5,5,5]] [[1,0,0,3,4,4],[1,2,0,2,3,2],[2,1,0,3,1,2],[1,0,1,3,3,1]] 10 [[1,2,3],[4,5,6],[7,8,9]] [[1,1,1,2,2,4],[1,0,0,1,1,2],[2,2,0,2,0,100]] 6 programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” ๋ˆ„์ ํ•ฉ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ด์šฉํ•ด ํ’€์–ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. (์ž์„ธํ•œ ์„ค๋ช…์€ ์นด์นด์˜ค ๊ณต์‹ ํ•ด์„ค์„ ์ฐธ๊ณ ํ•˜๋ฉด ๋” ์ดํ•ดํ•˜๊ธฐ ์ˆ˜์›”ํ•˜์‹ค ๊ฑฐ์—์š”!) 1. board์—์„œ ์—ด๊ณผ ํ–‰์ด +1๋งŒํผ์˜ ํฌ๊ธฐ์˜ ์ƒˆ๋กœ์šด ๋ณด๋“œ๋ฅผ 0์œผ๋กœ ์ฑ„์›Œ์ค€๋‹ค. var zeroBoard = Array(repeating: .. 2022. 1. 20.
[Swift] 2022 KAKAO BLIND RECRUITMENT ์–‘๊ณผ ๋Š‘๋Œ€ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์–‘๊ณผ ๋Š‘๋Œ€ [0,0,1,1,1,0,1,0,1,0,1,1] [[0,1],[1,2],[1,4],[0,8],[8,7],[9,10],[9,11],[4,3],[6,5],[4,6],[8,9]] 5 [0,1,0,1,1,0,1,0,0,1,0] [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6],[3,7],[4,8],[6,9],[9,10]] 5 programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” ์™„์ „ํƒ์ƒ‰๊ณผ DFS๋กœ ํ’€์–ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. 1. edge๋ฅผ ์ด์šฉํ•ด ๋ถ€๋ชจ์™€ ์ž์‹์„ ์—ฐ๊ฒฐํ•ด์ค๋‹ˆ๋‹ค. func connectEdge(_ edges:[[Int]]) { for edge in edges { if pc[edge[0]] == nil { pc[edge[0]] = [edg.. 2022. 1. 19.
[Swift] 2022 KAKAO BLIND RECRUITMENT ์–‘๊ถ๋Œ€ํšŒ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์–‘๊ถ๋Œ€ํšŒ ๋ฌธ์ œ ์„ค๋ช… ์นด์นด์˜ค๋ฐฐ ์–‘๊ถ๋Œ€ํšŒ๊ฐ€ ์—ด๋ ธ์Šต๋‹ˆ๋‹ค. ๋ผ์ด์–ธ์€ ์ €๋ฒˆ ์นด์นด์˜ค๋ฐฐ ์–‘๊ถ๋Œ€ํšŒ ์šฐ์Šน์ž์ด๊ณ  ์ด๋ฒˆ ๋Œ€ํšŒ์—๋„ ๊ฒฐ์Šน์ „๊นŒ์ง€ ์˜ฌ๋ผ์™”์Šต๋‹ˆ๋‹ค. ๊ฒฐ์Šน์ „ ์ƒ๋Œ€๋Š” ์–ดํ”ผ์น˜์ž…๋‹ˆ๋‹ค. ์นด์นด์˜ค๋ฐฐ ์–‘๊ถ๋Œ€ํšŒ ์šด์˜์œ„์› programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” DFS ๋ฐ ์™„์ „ํƒ์ƒ‰ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. 1. ๊ฐ ์ ์ˆ˜๋งˆ๋‹ค ์ด๊ธธ์ง€ ์งˆ์ง€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค. 10์ ๋ถ€ํ„ฐ 1์ ๊นŒ์ง€ ์–ดํ”ผ์น˜๋ฅผ ์ด๊ธธ ์ˆ˜ ์žˆ๋Š”์ง€๋ฅผ ํŒ๋ณ„ํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์ด๊ธธ ์ˆ˜ ์žˆ๋‹ค๋ฉด ํ•ด๋‹น ์ ์ˆ˜๋ฅผ ์–ป๋Š” ๋ฐฉ๋ฒ•๊ณผ ๊ทธ๋ƒฅ 0๋ฐœ์„ ์ด์„œ ๋‹ค๋ฅธ ์ ์ˆ˜๋ฅผ ์–ป์„ ๋ฐฉ๋ฒ•์„ ํƒํ•ฉ๋‹ˆ๋‹ค. DFS๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ด๊ธฐ๋Š” ๊ฒฝ์šฐ์™€ ๊ทธ๋ƒฅ 0๋ฐœ์„ ์˜๊ณ  ๋‹ค์Œ ๋‹จ๊ณ„๋กœ ๋„˜์–ด๊ฐˆ ๊ฒฝ์šฐ 2๊ฐ€์ง€๋ฅผ ์žฌ๊ท€ํ•ด์ค๋‹ˆ๋‹ค. func dfs(leftArrow:Int,depth:Int,history:[Int],info:[.. 2022. 1. 19.
[Swift] 2022 KAKAO BLIND RECRUITMENT ์ฃผ์ฐจ ์š”๊ธˆ ๊ณ„์‚ฐ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์ฃผ์ฐจ ์š”๊ธˆ ๊ณ„์‚ฐ [180, 5000, 10, 600] ["05:34 5961 IN", "06:00 0000 IN", "06:34 0000 OUT", "07:59 5961 OUT", "07:59 0148 IN", "18:59 0000 IN", "19:09 0148 OUT", "22:59 5961 IN", "23:00 5961 OUT"] [14600, 34400, 5000] programmers.co.kr Solution 1. records์˜ ๊ธฐ๋ก๋Œ€๋กœ ์‹œ๊ฐ„์„ ๊ณ„์‚ฐํ•ด ์ €์žฅํ•œ๋‹ค. var timeInfo:[String:Int] = [:] var parkInfo:[String:Int] = [:] func calTimeByRecord(_ records:[String],_ parkIn.. 2022. 1. 19.
[Swift] 2022 KAKAO BLIND RECRUITMENT k์ง„์ˆ˜์—์„œ ์†Œ์ˆ˜ ๊ฐœ์ˆ˜ ๊ตฌํ•˜๊ธฐ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - k์ง„์ˆ˜์—์„œ ์†Œ์ˆ˜ ๊ฐœ์ˆ˜ ๊ตฌํ•˜๊ธฐ ๋ฌธ์ œ ์„ค๋ช… ์–‘์˜ ์ •์ˆ˜ n์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ์ด ์ˆซ์ž๋ฅผ k์ง„์ˆ˜๋กœ ๋ฐ”๊ฟจ์„ ๋•Œ, ๋ณ€ํ™˜๋œ ์ˆ˜ ์•ˆ์— ์•„๋ž˜ ์กฐ๊ฑด์— ๋งž๋Š” ์†Œ์ˆ˜(Prime number)๊ฐ€ ๋ช‡ ๊ฐœ์ธ์ง€ ์•Œ์•„๋ณด๋ ค ํ•ฉ๋‹ˆ๋‹ค. 0P0์ฒ˜๋Ÿผ ์†Œ์ˆ˜ ์–‘์ชฝ์— 0์ด ์žˆ๋Š” ๊ฒฝ์šฐ P0์ฒ˜๋Ÿผ ์†Œ programmers.co.kr Solution 1. n์„ k์ง„์ˆ˜๋กœ ๋ฐ”๊พผ๋‹ค. let change = String(n,radix: k) 2. ๋ฐ”๊พผ ๋ฌธ์ž๋ฅผ 0์„ ๊ธฐ์ค€์œผ๋กœ ๋‚˜๋ˆˆ๋‹ค. let numbers = change.split(separator: "0") 3. ์†Œ์ˆ˜์ธ์ง€ ํŒ๋ณ„ํ•œ๋‹ค. func isPrimeNumber(_ n:Int) -> Bool { if n == 1 { return false } if n == 2 || n == 3 {.. 2022. 1. 19.
[Swift] 2022 KAKAO BLIND RECRUITMENT ์‹ ๊ณ  ๊ฒฐ๊ณผ ๋ฐ›๊ธฐ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์‹ ๊ณ  ๊ฒฐ๊ณผ ๋ฐ›๊ธฐ ๋ฌธ์ œ ์„ค๋ช… ์‹ ์ž…์‚ฌ์› ๋ฌด์ง€๋Š” ๊ฒŒ์‹œํŒ ๋ถˆ๋Ÿ‰ ์ด์šฉ์ž๋ฅผ ์‹ ๊ณ ํ•˜๊ณ  ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ๋ฉ”์ผ๋กœ ๋ฐœ์†กํ•˜๋Š” ์‹œ์Šคํ…œ์„ ๊ฐœ๋ฐœํ•˜๋ ค ํ•ฉ๋‹ˆ๋‹ค. ๋ฌด์ง€๊ฐ€ ๊ฐœ๋ฐœํ•˜๋ ค๋Š” ์‹œ์Šคํ…œ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ฐ ์œ ์ €๋Š” ํ•œ ๋ฒˆ์— ํ•œ ๋ช…์˜ programmers.co.kr Solution 1. id_list๋ฅผ ์ธ๋ฑ์Šค์— ๋งž๊ฒŒ ๋”•์…”๋„ˆ๋ฆฌ์— ๋‹ด๋Š”๋‹ค. var idNumber:[String:Int] = [:] for (i,id) in id_list.enumerated() { idNumber[id] = i } 2. ์‹ ๊ณ  ๋‹นํ•œ ์‚ฌ๋žŒ์„ ํ‚ค๊ฐ’์œผ๋กœ,์‹ ๊ณ ํ•œ ์‚ฌ๋žŒ๋“ค์„ ๋ฐธ๋ฅ˜๊ฐ’์œผ๋กœ ๋”•์…”๋„ˆ๋ฆฌ์— ๋‹ด๋Š”๋‹ค. var reportInfo:[String:Set] = [:] for r in report { let split = r.split(sepa.. 2022. 1. 19.
[Swift] 2020 KAKAO BLIND RECRUITMENT ๊ฐ€์‚ฌ ๊ฒ€์ƒ‰  Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๊ฐ€์‚ฌ ๊ฒ€์ƒ‰ programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” Trie ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํ’€์–ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. (Trie ๊ด€๋ จํ•ด์„œ๋Š” ๋”ฐ๋กœ ์ •๋ฆฌํ•ด์„œ ์˜ฌ๋ฆฌ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!ใ…œ) 1. Trie ์ž๋ฃŒ ๊ตฌ์กฐ๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค. ์ •์„์œผ๋กœ ๋งŒ๋“ ๊ฑด ์•„๋‹ˆ๊ณ  ๊ฐ„๋‹จํ•˜๊ฒŒ ๋‹จ์–ด๋ฅผ Trie ์ž๋ฃŒ๊ตฌ์กฐ์— ๋งž๊ฒŒ ์‚ฝ์ž…ํ•˜๋Š” insert ๋ฉ”์„œ๋“œ์™€ ๊ธ€์ž์˜ ์ž์‹์ด ๋ช‡ ๊ฐœ ์žˆ๋Š”์ง€ ์„ธ์–ด์ฃผ๋Š” getCount ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค. class Node { var value:String var count:Int = 0 var children:[String:Node] = [:] init(value:String) { self.value = value } func append(_ value:String) { se.. 2022. 1. 3.
[Swift] 2019 KAKAO BLIND RECRUITMENT ๋ฌด์ง€์˜ ๋จน๋ฐฉ ๋ผ์ด๋ธŒ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋ฌด์ง€์˜ ๋จน๋ฐฉ ๋ผ์ด๋ธŒ programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” ํšจ์œจ์„ฑ์ด ํ•ต์‹ฌ์ธ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. food_times๊ฐ€ ์ตœ๋Œ€ 1์–ต, k๊ฐ€ ์ตœ๋Œ€ 2*10^13์ด๊ธฐ ๋•Œ๋ฌธ์— ๋‹จ์ˆœํžˆ 0์ดˆ๋ถ€ํ„ฐ ์‹œ๊ฐ„์„ ์žฌ๋ฉฐ ์Œ์‹์„ ํ™•์ธํ•˜๊ธฐ์—” ๋„ˆ๋ฌด ํฐ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฝ๋‹ˆ๋‹ค. 1. ์Œ์‹์ด ๋‚จ์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๋ฅผ ์ •์˜ํ•œ๋‹ค. ์Œ์‹์„ ๋จน๋Š” ์‹œ๊ฐ„์„ ๋ชจ๋‘ ํ•ฉ์ณ๋„ k๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์œผ๋ฉด k์‹œ๊ฐ„์— ๋‚จ๋Š” ์Œ์‹์ด ์—†์Šต๋‹ˆ๋‹ค. if food_times.reduce(0,+) $1.element} 3. ๋‚จ์€ ์Œ์‹ ์ˆ˜์™€ ์ตœ์†Œ ์‹œ๊ฐ„์„ ๊ณฑํ•˜์—ฌ k์—์„œ ๋นผ์ค€๋‹ค. ํ•œ๋ฒˆ์— ์Œ์‹ ์ˆ˜๋ฅผ ๊ฐ€์žฅ ๋งŽ์ด ๋บ„ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์€ ํ˜„์žฌ ๋‚จ์€ ์Œ์‹ ์ˆ˜์™€ ๊ฐ€์žฅ ์ตœ์†Œ๊ฐ’์„ ๊ณฑํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์ฆ‰, [3,5,6,7,8,9,4,4,3,3]๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๋ฉด ํ˜„์žฌ ๋‚จ์€ .. 2021. 12. 15.
[Swift] 2020 KAKAO BLIND RECRUITMENT ์™ธ๋ฒฝ ์ ๊ฒ€ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์™ธ๋ฒฝ ์ ๊ฒ€ ๋ ˆ์Šคํ† ๋ž‘์„ ์šด์˜ํ•˜๊ณ  ์žˆ๋Š” "์Šค์นดํ”ผ"๋Š” ๋ ˆ์Šคํ† ๋ž‘ ๋‚ด๋ถ€๊ฐ€ ๋„ˆ๋ฌด ๋‚ก์•„ ์นœ๊ตฌ๋“ค๊ณผ ํ•จ๊ป˜ ์ง์ ‘ ๋ฆฌ๋ชจ๋ธ๋ง ํ•˜๊ธฐ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค. ๋ ˆ์Šคํ† ๋ž‘์ด ์žˆ๋Š” ๊ณณ์€ ์Šค๋…ธ์šฐํƒ€์šด์œผ๋กœ ๋งค์šฐ ์ถ”์šด ์ง€์—ญ์ด์–ด์„œ ๋‚ด๋ถ€ ๊ณต์‚ฌ๋ฅผ ํ•˜ programmers.co.kr Solution 1. Set๋กœ ๋œ ์ทจ์•ฝ์ ๋“ค์ด ๋‹ด์„ weaks ๋ณ€์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด์ค๋‹ˆ๋‹ค. Set๋กœ ๋งŒ๋“ค์–ด์ฃผ๋Š” ์ด์œ ๋Š” ์ทจ์•ฝ์ ๋“ค์ด ๊ฐ™์€ ๊ฒƒ๋“ค์˜ ๋ฐ˜๋ณต์„ ํ”ผํ•˜๊ธฐ ์œ„ํ•ด์„œ์ž…๋‹ˆ๋‹ค.(์‹œ๊ฐ„์ดˆ๊ณผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด) var weaks:Set = [weak] 2. ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฑฐ๋ฆฌ๊ฐ€ ํฐ ์นœ๊ตฌ๋ถ€ํ„ฐ ์ฐจ๋ก€๋กœ ์ˆœํšŒํ•œ๋‹ค. ์ตœ๋Œ€ํ•œ ์ ์€ ์นœ๊ตฌ๋ฅผ ์ด์šฉํ•ด์•ผ ํ•˜๋ฏ€๋กœ ๊ฑฐ๋ฆฌ๊ฐ€ ํฐ ์นœ๊ตฌ๋ถ€ํ„ฐ ์ˆœํšŒํ•ฉ๋‹ˆ๋‹ค. for (i,d) in dist.reversed().enumerated() { ... 3. ์ด๋ฏธ .. 2021. 9. 8.
728x90
๋ฐ˜์‘ํ˜•