μΌ | μ | ν | μ | λͺ© | κΈ | ν |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- dfs
- WebView
- λ°±νΈλνΉ
- νλ‘κ·Έλλ¨Έμ€
- λ°±μ€
- λμ ν©
- Swift
- μ€ν
- BFS
- μ΄μ§νμ
- λΈλ£¨νΈν¬μ€
- WebApp
- 그리λ μκ³ λ¦¬μ¦
- λΆν μ 볡
- λΆν μ 볡
- SwiftUI
- μκ³ λ¦¬μ¦
- λΉνΈμ°μ°μ
- μμ
- λΈλ£¨νΈν¬μ€ μκ³ λ¦¬μ¦
- ios
- μ½ν
- λΆν νμ
- dp
- μ ν΄λ¦¬λ νΈμ λ²
- λ¬Έμμ΄
- μ½λ©ν μ€νΈ
- Queue
Archives
- Today
- Total
MUKER_DEV with iOS
[swift] νλ‘κ·Έλλ¨Έμ€ - μΉμμ΄ (2) λ³Έλ¬Έ
νλ‘κ·Έλλ¨Έμ€
μ½λ μ€μ¬μ κ°λ°μ μ±μ©. μ€ν κΈ°λ°μ ν¬μ§μ 맀μΉ. νλ‘κ·Έλλ¨Έμ€μ κ°λ°μ λ§μΆ€ν νλ‘νμ λ±λ‘νκ³ , λμ κΈ°μ κΆν©μ΄ μ λ§λ κΈ°μ λ€μ λ§€μΉ λ°μΌμΈμ.
programmers.co.kr
λ¬Έμ νΈλ λ° μμ΄ λμμ΄ λλλ‘ λμ νμ΄μ κ°μ λ νμ΄λ₯Ό μ¬λ¦½λλ€.
λν νμ΄ ν λ€λ₯Έ μ¬λμ νμ΄λ₯Ό λ³΄κ³ μ°Έκ³ ν λ§ν νμ΄λ μ¬λ¦½λλ€.
- λ¬Έμ μ λ°λΌ λμ νμ΄λ§ μμ μ μμ΅λλ€.
- ν΄λΉ νμ΄λ€μ νμ΄ μ€ νλμΌ λΏ μ΅μ μ νμ΄λ μλ μ μμ΅λλ€.
λ¬Έμ μ€λͺ
- μΉμμ΄μ μ’ λ₯λ "aya", "ye", "woo", "ma" μ λλ€.
- μ νν μΉμμ΄λ‘λ§ λ°μν λ¬Έμμ΄μ κ°μλ₯Ό ꡬν΄μΌνλ λ¬Έμ μ λλ€.
- μ°μν΄μ κ°μ λ°μμ νλ건 μ νν μΉμμ΄μΌμ§λΌλ κ°μλ‘ μΉμ§ μμ΅λλ€.
λμ νμ΄
import Foundation
func solution(_ babbling:[String]) -> Int {
var correct = Array(repeating: "", count: babbling.count) // λΉλ°°μ΄ μ΄κΈ°ν
for (index,i) in babbling.enumerated() {
var temp = ""
var before = ""
for j in i {
temp.append(j) // λ¬Έμ νλμ© tempμ λ£μ΄μ£ΌκΈ°
if temp == "aya" || temp == "ye" || temp == "woo" || temp == "ma" { // μΉμμ΄κ° μμ±λλ©΄ tempκ° correctμ λ£μ΄μ£ΌκΈ°
if before == temp { correct[index] = ""; continue } // μ μ λ¬Έμμ κ°λ€λ©΄ ""λ‘ λ§λ€μ΄λ²λ¦¬κΈ°
correct[index] += temp
before = temp
temp = ""
}
}
}
return correct.enumerated().filter { $0.element == babbling[$0.offset] }.count // correctκ°κ³Ό babblingκ°μ΄ κ°μ κ²λ§ return
}
μ°Έκ³ ν λ§ν νμ΄
import Foundation
func solution(_ babbling:[String]) -> Int {
var count: Int = 0
for element in babbling {
var str = String(element)
str = str.replacingOccurrences(of: "aya", with: "1")
str = str.replacingOccurrences(of: "ye", with: "2")
str = str.replacingOccurrences(of: "woo", with: "3")
str = str.replacingOccurrences(of: "ma", with: "4")
if Int(str) != nil && !str.contains("11") && !str.contains("22") && !str.contains("33") && !str.contains("44"){
count += 1
}
}
return count
}
func solution(_ babbling: [String]) -> Int {
return babbling.filter { $0.range(of: "^(aya(?!aya)|ye(?!ye)|woo(?!woo)|ma(?!ma))+$", options: .regularExpression) != nil }.count
}
'π€ μκ³ λ¦¬μ¦ > programmers' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[swift] νλ‘κ·Έλλ¨Έμ€ - λλ§μ μνΈ (0) | 2023.02.16 |
---|---|
[swift] νλ‘κ·Έλλ¨Έμ€ - κ°μΈμ 보 μμ§ μ ν¨κΈ°κ° (0) | 2023.02.14 |
[swift] νλ‘κ·Έλλ¨Έμ€ - μ κ³ κ²°κ³Ό λ°κΈ° (0) | 2023.02.10 |
[swift] νλ‘κ·Έλλ¨Έμ€ - μ«μ μ§κΏ (0) | 2023.02.09 |
[swift] νλ‘κ·Έλλ¨Έμ€ - 체μ‘볡 (0) | 2023.02.07 |