๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป iOSun
article thumbnail
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 86971] ์ „๋ ฅ๋ง์„ ๋‘˜๋กœ ๋‚˜๋ˆ„๊ธฐ swift

๋ฌธ์ œ ํ’€์ด DFS๋ฅผ ์ด์šฉํ•ด์„œ ํ’€์—ˆ๋‹ค. 1. ์ด์ค‘๋ฐฐ์—ด์— ์—ฐ๊ฒฐ์ ์„ ๋„ฃ๋Š”๋‹ค. (vertex๋Š” 1๋ถ€ํ„ฐ ์‹œ์ž‘์ด๊ธฐ ๋•Œ๋ฌธ์— 0์€ ๋น„์›Œ๋‘ ) ex) [[], [3], [3], [1,2,4]] 2. wires๋ฅผ ํฌ๋ฌธ์„ ๋Œ๋ฆฌ๋ฉฐ ์—ฐ๊ฒฐ์ ์„ ์ œ๊ฑฐํ•ด๋ณธ๋‹ค. 3. ํ•˜๋‚˜ ์ œ๊ฑฐํ•œ ์ƒํƒœ์—์„œ DFS๋ฅผ ๋Œ๋ ค๋ณธ๋‹ค. ์ด๋•Œ DFS๋Š” DFS(๊ทธ๋ž˜ํ”„, ํ˜„์žฌ์ •์ )์ด๊ณ  DFS๊ฐ€ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๋๊นŒ์ง€ ๊ฐ”์„ ๋•Œ ๋ฐฉ๋ฌธํ•œ ์ •์  ๊ฐœ์ˆ˜ count๋ฅผ ๊ตฌํ•œ๋‹ค. (ํ•œ ์ชฝ์˜ depth๋งŒ ๊ตฌํ•ด๋„ ๋‹ค๋ฅธ ํ•œ์ชฝ์˜ ๊ฐœ์ˆ˜๋ฅผ ์•Œ ์ˆ˜ ์žˆ๊ธฐ๋•Œ๋ฌธ์— ๊ทธ๋ƒฅ 1๋ถ€ํ„ฐ ๋Œ๋ฆฌ๊ณ  ๋๊นŒ์ง€ ๊ฐ€๋ณธ๋‹ค.) 4. wires ํ•˜๋‚˜ ์ œ๊ฑฐํ• ๋•Œ๋งˆ๋‹ค ์†ก์ „ํƒ‘์˜ ๊ฐœ์ˆ˜ ์ฐจ์ด๋ฅผ ๊ตฌํ•œ๋‹ค. (๋‹ค์Œ wires๋บ„๋•Œ visited, count ์ดˆ๊ธฐํ™”) ์ฝ”๋“œ func solution(_ n:Int, _ wires:[[Int]]) -> Int..

article thumbnail
[Swift Language Guide] ARC
Swift Language Guide 2023. 9. 7. 22:21

ARC ์ž๋™ ์ฐธ์กฐ ์นด์šดํŒ… Automatic Reference Counting swift๋Š” ARC๋กœ ์ธ์Šคํ„ด์Šค๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š์„ ๋•Œ ์ž๋™์œผ๋กœ ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น์„ ํ•ด์ค€๋‹ค. ๋‹น์—ฐํ•˜๊ฒŒ๋„ struct์™€ enum์€ ๊ฐ’์„ ๋ณต์‚ฌํ•˜๋Š” valueํƒ€์ž…์ด๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹น๋˜์ง€ ์•Š๊ณ  ์ฐธ์กฐ ํƒ€์ž…์ธ class์˜ ์ธ์Šคํ„ด์Šค์—๋งŒ ์ฐธ์กฐ ์นด์šดํŒ…์ด ์ ์šฉ๋œ๋‹ค. ์ž๋ฐ”์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ€๋น„์ง€ ์ฝœ๋ ‰์…˜(GC)์™€ ๋‹ค๋ฅธ์ ์€ GC๋Š” ๋Ÿฐํƒ€์ž„๋•Œ ๊ณ„์† ์ฐธ์กฐ๋ฅผ ์ถ”์ ํ•˜๊ณ  RC๋Š” ์ปดํŒŒ์ผ๋•Œ ๋ชจ๋‘ ๊ฒฐ์ •์ด ๋‚œ๋‹ค๋Š” ์ฐจ์ด์ ์ด ์žˆ๋‹ค. ARC์˜ ์ž‘๋™ ์›๋ฆฌ ํด๋ž˜์Šค์˜ ์ƒˆ๋กœ์šด ์ธ์Šคํ„ด์Šค๊ฐ€ ์ƒ์„ฑ๋  ๋•Œ๋งˆ๋‹ค ARC๋Š” ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น์„ ํ•ด์คŒ ์ธ์Šคํ„ด์Šค๊ฐ€ ๋”์ด์ƒ ํ•„์š”์น˜ ์•Š์„ ๋•Œ ARC๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น์„ ํ•ด์ œ ํ•ด์คŒ ์‚ฌ์šฉ์ค‘์ธ ์ธ์Šคํ„ด์Šค๋ฅผ ๋ฉ”๋ชจ๋ฆฌ ํ•ด์ œํ•˜๋ฉด ์•ˆ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์ธ์Šคํ„ด์Šค์— ๊ฐ•ํ•œ ์ฐธ์กฐ (strong reference)..

article thumbnail
[Swift Language Guide] ํ”„๋กœํ† ์ฝœ (Protocols)
Swift Language Guide 2023. 8. 1. 21:25

ํ”„๋กœํ† ์ฝœ (Protocols) ๋”ฐ๋ผ์•ผํ•˜๋Š” ์š”๊ตฌ ์‚ฌํ•ญ์„ ์ •์˜ํ•œ๋‹ค. class SomeClass: SomeSuperclass, FirstProtocol, AnotherProtocol { // class definition goes here } ์ž‘์„ฑ ์ˆœ์„œ : ๋ถ€๋ชจํด๋ž˜์Šค ๋จผ์ € ์ž‘์„ฑํ•˜๊ณ  ๊ทธ ๋‹ค์Œ์— ํ”„๋กœํ† ์ฝœ์„ ์ฑ„ํƒํ•œ๋‹ค. protocol SomeProtocol { var mustBeSettable: Int { get set } var doesNotNeedToBeSettable: Int { get } } ๊ฐ ํ”„๋กœํผํ‹ฐ๊ฐ€ gettable ์ธ์ง€ gettable๊ณผ settable ์ธ์ง€ ์ง€์ •ํ•ด์ค˜์•ผ ํ•จ mutating ๋ฉ”์†Œ๋“œ ์š”๊ตฌ์‚ฌํ•ญ protocol Togglable { mutating func toggle() } enum On..

article thumbnail
[Swift Language Guide] ํด๋ž˜์Šค ์ƒ์†๊ณผ ์ดˆ๊ธฐํ™” (Class Inheritance and Initialization)
Swift 2023. 6. 20. 22:29

ํด๋ž˜์Šค๋Š” ๊ตฌ์กฐ์ฒด์™€ ๋‹ค๋ฅด๊ฒŒ ๋ฉค๋ฒ„์™€์ด์ฆˆ ์ด๋‹ˆ์…œ๋ผ์ด์ €๊ฐ€ ์—†์Œ ํ•„์ˆ˜๋กœ ๊ตฌํ˜„ํ•ด์•ผ ํ•จ ์ง€์ • ์ƒ์„ฑ์ž(Designated Initializer) class Anmimal { let name: String let age: Int init(name: String, age: Int) { self.name = name self.age = age } } ๋ชจ๋“  ํ”„๋กœํผํ‹ฐ๋ฅผ ์™„๋ฒฝํ•˜๊ฒŒ ์ดˆ๊ธฐํ™”ํ•จ ์˜ต์…”๋„ ํ”„๋กœํผํ‹ฐ์ด๊ฑฐ๋‚˜ ๊ธฐ๋ณธ๊ฐ’์„ ๊ฐ€์ง„ ํ”„๋กœํผํ‹ฐ๋Š” ์˜ˆ์™ธ ๋ชจ๋“  ํด๋ž˜์Šค๋Š” ์ ์–ด๋„ 1๊ฐœ ์ด์ƒ์˜ ์ง€์ • ์ƒ์„ฑ์ž๋ฅผ ๊ฐ€์ง ๋ฐ˜๋“œ์‹œ ์ž์‹ ํด๋ž˜์Šค์˜ ์ง€์ • ์ƒ์„ฑ์ž๋Š” ๋ถ€๋ชจ ํด๋ž˜์Šค์˜ ์ง€์ • ์ƒ์„ฑ์ž๋ฅผ ํ˜ธ์ถœํ•ด์•ผ ํ•จ ํŽธ์˜ ์ƒ์„ฑ์ž (Convenience Initializers) class Anmimal { let name: String let age: Int init(name: ..

profile on loading

Loading...