[Swift] ๋ฐฑ์ค€ 7569 ํ† ๋งˆํ† 
ยท
๐Ÿ“ ์ฝ”ํ…Œ/BOJ
import Foundation let MNH = readLine()!.split(separator: " ").map { Int($0)! } let M = MNH[0] // ์—ด let N = MNH[1] // ํ–‰ let H = MNH[2] // ๋ฉด var board = [[[Int]]]() for _ in 0..
[Swift] ๋ฐฑ์ค€ 1926 ๊ทธ๋ฆผ
ยท
๐Ÿ“ ์ฝ”ํ…Œ/BOJ
import Foundation let nm = readLine()!.components(separatedBy: " ").map { Int($0)! } let n = nm[0] let m = nm[1] var board = [[Int]]() for _ in 0..
BFS
ยท
๐Ÿ“ ์ฝ”ํ…Œ/์œ ํ˜•์ •๋ฆฌ
BFS(Breadth First Search) ๋‹ค์ฐจ์› ๋ฐฐ์—ด์—์„œ ๊ฐ ์นธ์„ ๋ฐฉ๋ฌธํ•  ๋•Œ ๋„ˆ๋น„๋ฅผ ์šฐ์„ ์œผ๋กœ ๋ฐฉ๋ฌธํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ตฌํ˜„๋ฐฉ๋ฒ• 1. ์‹œ์ž‘ํ•˜๋Š” ์นธ์„ ํ์— ๋„ฃ๊ณ  ๋ฐฉ๋ฌธํ–ˆ๋‹ค๋Š” ํ‘œ์‹œ๋ฅผ ๋‚จ๊น€ 2. ํ์—์„œ ์›์†Œ๋ฅผ ๊บผ๋‚ด์–ด ๊ทธ ์นธ์— ์ƒํ•˜์ขŒ์šฐ๋กœ ์ธ์ ‘ํ•œ ์นธ์— ๋Œ€ํ•ด 3๋ฒˆ์„ ์ง„ํ–‰ 3. ํ•ด๋‹น ์นธ์„ ์ด์ „์— ๋ฐฉ๋ฌธํ–ˆ๋‹ค๋ฉด ์•„๋ฌด ๊ฒƒ๋„ ํ•˜์ง€ ์•Š๊ณ , ์ฒ˜์Œ์œผ๋กœ ๋ฐฉ๋ฌธํ–ˆ๋‹ค๋ฉด ๋ฐฉ๋ฌธํ–ˆ๋‹ค๋Š” ํ‘œ์‹œ๋ฅผ ๋‚จ๊ธฐ๊ณ  ํ•ด๋‹น ์นธ์„ ํ์— ์‚ฝ์ž… 4. ํ๊ฐ€ ๋นŒ ๋•Œ๊นŒ์ง€ 2๋ฒˆ์„ ๋ฐ˜๋ณต ๋ชจ๋“  ์นธ์ด ํ์— 1๋ฒˆ์”ฉ ๋“ค์–ด๊ฐ€๋ฏ€๋กœ ์‹œ๊ฐ„๋ณต์žก๋„๋Š” ์นธ์ด N๊ฐœ์ผ ๋•Œ O(N). ์˜ˆ์‹œ์ฝ”๋“œ import Foundation let board: [[Int]] = [ [1,1,1,0,1,0,0,0,0,0], [1,0,0,0,1,0,0,0,0,0], [1,1,1,0,1,0,0,0,0,0], [1,1,0,0,1,..
[๊ตฌํ˜„] Extra Long Factorials
ยท
๐Ÿ“ ์ฝ”ํ…Œ/HackerRank
ํ’€์ด ์—„์ฒญ ํฐ ์ˆ˜์˜ ํŒฉํ† ๋ฆฌ์–ผ์„ ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ๋‹ค. ์ˆ˜๊ฐ€ ๋„ˆ๋ฌด ํฌ๊ธฐ ๋•Œ๋ฌธ์— ์ˆ˜๋ฅผ ๋ฐฐ์—ด๋กœ ๋‚˜๋ˆ ์„œ ํ’€์–ด์•ผํ•œ๋‹ค. temp๋ผ๋Š” ์ž„์‹œ๋ฐฐ์—ด์„ ์—ญ์ˆœ์œผ๋กœ ์ˆœํšŒํ•˜๋ฉด์„œ ํ˜„์žฌ ์ˆซ์ž์™€ ์ด์ „๋‹จ๊ณ„์—์„œ์˜ ๋‚˜๋จธ์ง€๋ฅผ ๋”ํ•œ๋‹ค. ๊ทธ ์ดํ•ฉ์„ 10์œผ๋กœ ๋‚˜๋ˆ„ ๋ชซ์ด ์ƒˆ๋กœ์šด ๋‚˜๋จธ์ง€๊ฐ€ ๋œ๋‹ค. ์ƒˆ๋กœ์šด ๋‚˜๋จธ์ง€๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ result ๋ฌธ์ž์—ด์˜ ์•ž์ชฝ์— ์‚ฝ์ž…ํ•œ๋‹ค. ์ด๊ฒƒ์„ ์žฌ๊ท€๋กœ ๋ฐ˜๋ณตํ•˜์—ฌ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ์ฝ”๋“œ func extraLongFactorials(n: Int) -> Void { // Write your code here var result = "1" for num in 1...n { result = multiply(result, by: num) } print(result) } func multiply(_ a: String, by: Int) ->..
[๊ตฌํ˜„] Picking Numbers
ยท
๐Ÿ“ ์ฝ”ํ…Œ/HackerRank
func pickingNumbers(a: [Int]) -> Int { // Write your code here let uniqueArr = Array(Set(a)) var arr = [Int]() var res = [Int]() var max = 0 for n in uniqueArr { for e in a { if n - e = 0 { arr.append(n-e) } } if arr.count > max { max = arr.count res = arr } arr = [] } return res.count }
[๊ตฌํ˜„] Climbing the Leaderboard
ยท
๐Ÿ“ ์ฝ”ํ…Œ/HackerRank
https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem?isFullScreen=true Climbing the Leaderboard | HackerRank Help Alice track her progress toward the top of the leaderboard! www.hackerrank.com func climbingLeaderboard(ranked: [Int], player: [Int]) -> [Int] { var res = Array(repeating: 0, count: player.count) var uniqueRanked = [Int]() for score in ranked { if let lastScore = un..
[Swift] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค60061 ๊ธฐ๋‘ฅ๊ณผ ๋ณด ์„ค์น˜
ยท
๐Ÿ“ ์ฝ”ํ…Œ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค
import Foundation func solution(_ n:Int, _ build_frame:[[Int]]) -> [[Int]] { var answer = Set() func canConstruct() -> Bool { for structure in answer { let x = structure[0], y = structure[1], a = structure[2] // ๊ธฐ๋‘ฅ if a == 0 { if answer.contains([x - 1, y, 1]) || answer.contains([x, y, 1]) || answer.contains([x, y - 1, 0]) || y == 0 { continue } return false } // ๋ณด else { if answer.contains([x, ..
[Swift] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค12911 ๋‹ค์Œ ํฐ ์ˆซ์ž
ยท
๐Ÿ“ ์ฝ”ํ…Œ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค
import Foundation func solution(_ n:Int) -> Int { var answer : Int = n + 1 while true { if n.nonzeroBitCount == answer.nonzeroBitCount { break; } answer += 1 } return answer } n.nonzeroBitcount : ๋น„ํŠธ์—์„œ 1์˜๊ฐœ์ˆ˜ ์„ธ์ค€๋‹ค. import Foundation func solution(_ n:Int) -> Int { let countOne = countBinaryOne(n); for num in n+1...Int.max { if countBinaryOne(num) == countOne { return num; } } return n } func countBi..
[Swift] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค42862 ์ฒด์œก๋ณต
ยท
๐Ÿ“ ์ฝ”ํ…Œ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค
import Foundation func solution(_ n:Int, _ lost:[Int], _ reserve:[Int]) -> Int { var lost = lost.sorted(by:
[Swift] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค154539 ๋’ค์— ์žˆ๋Š” ํฐ ์ˆ˜ ์ฐพ๊ธฐ
ยท
๐Ÿ“ ์ฝ”ํ…Œ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค
import Foundation func solution(_ numbers: [Int]) -> [Int] { var stack = [Int]() var res = Array(repeating: -1, count: numbers.count) for i in 0..
JerryiOS
'๐Ÿ“ ์ฝ”ํ…Œ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก