From 38b311b80291e1d6cb41d41fc41237b7a6ea8d49 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Sat, 10 Jan 2026 22:46:44 +0900 Subject: [PATCH] baekjoon 20260110 --- code_study/Baekjoon/swift/12015.swift | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 code_study/Baekjoon/swift/12015.swift diff --git a/code_study/Baekjoon/swift/12015.swift b/code_study/Baekjoon/swift/12015.swift new file mode 100644 index 0000000..7955e7e --- /dev/null +++ b/code_study/Baekjoon/swift/12015.swift @@ -0,0 +1,43 @@ +func solve() -> Int { + guard let N = Int(readLine() ?? ""), + let input = readLine() + else { return 0 } + + let A: [Int] = input.split(separator: " ").compactMap{Int($0)} + if A.count != N { return -1 } + + var LIS: [Int] = [] + + for now in A { + if LIS.isEmpty { + LIS.append(A[0]) + continue + } + + guard let lastNum: Int = LIS.last else { break } + + if lastNum < now { + LIS.append(now) + } + else { + var l = 0, r = LIS.count-1 + + while l < r { + let mid: Int = (l+r)/2 + + if LIS[mid] < now { + l = mid + 1 + } + else { + r = mid + } + } + + LIS[l] = now + } + } + + return LIS.count +} + +print(solve())