프로그래머스 - 내적
·
Algorithm/programmers
import Foundationfunc solution(_ a:[Int], _ b:[Int]) -> Int { return Array(0..
프로그래머스 - 2021 카카오 블라인드 신규 아이디 추천 (정규 표현식)
·
Algorithm/programmers
정규 표현식으로 문제를 해결하면 쉽게 해결할 수 있게 됩니다 정규 표현식은 "[^a-z0-9-_.]" 으로 표현하게 된다면a 부터 z 까지 소문자들을 포함하면서0 부터 9 까지 숫자들을 포함하면서- 하고 _ 그리고 . 을 포함한 것들을 제외한 것들을 "" 빈값으로 대체할 수 있게 됩니다.import Foundationfunc solution(_ new_id:String) -> String { var id = new_id id = id.lowercased() id = id.replacingOccurrences(of: "[^a-z0-9-_.]", with: "", options: .regularExpression) while id.contains("..") { id ..
프로그래머스 - 음양 더하기
·
Algorithm/programmers
import Foundationfunc solution(_ absolutes:[Int], _ signs:[Bool]) -> Int { return Array(0..
프로그래머스 - 로또의 최고 순위와 최저 순위
·
Algorithm/programmers
import Foundationfunc solution(_ lottos:[Int], _ win_nums:[Int]) -> [Int] { let rank = [6,5,4,3,2] let lottoSet: Set = Set(lottos) let win_numSet: Set = Set(win_nums) let inter = lottoSet.intersection(win_numSet) var first = inter.count + lottos.filter { $0 == 0 }.count first = (first >= 2) ? rank.firstIndex(of: first)!+1 : 6 var last = inter.count last = (last >= 2) ? (r..
프로그래머스 - 바탕화면 정리
·
Algorithm/programmers
import Foundationfunc solution(_ wallpaper:[String]) -> [Int] { var wallpapers: [(Int,Int)] = [] var minX = Int.max var minY = Int.max var maxX = Int.min var maxY = Int.min for (y, value1) in wallpaper.enumerated() { for (x, value2) in value1.enumerated() { if value2 == "#" { wallpapers.append((y, x)) minX = min(minX, ..
프로그래머스 - 공원 산책
·
Algorithm/programmers
1.import Foundationfunc solution(_ park:[String], _ routes:[String]) -> [Int] { var currentY = 0 var currentX = 0 var obstacles: [(Int,Int)] = [] for (y,value) in park.enumerated() { for (x, value2) in value.map({ String($0) }).enumerated() { if value2 == "S" { currentX = x currentY = y } else if value2 == "X" { ..
ytw_developer
'Algorithm' 카테고리의 글 목록 (7 Page)