import Foundation
func solution(_ t:String, _ p:String) -> Int {
let len = p.count
var answer = 0
for i in 0..<t.count-len+1 {
let startIndex = t.index(t.startIndex, offsetBy: i)
let endIndex = t.index(t.startIndex, offsetBy: i+len-1)
let range = startIndex...endIndex
if Int64(t[range])! <= Int64(p)! {
answer += 1
}
}
return answer
}
import Foundation
func solution(_ t: String, _ p: String) -> Int {
var answer = 0
for i in 0 ... t.count - p.count {
let subStr = t.dropFirst(i).prefix(p.count)
if let comp = Int(subStr), let val = Int(p) {
answer += comp - val <= 0 ? 1 : 0
}
}
return answer
}
서브스트링 추출
let subStr = t.dropFirst(i).prefix(p.count)