Skip to content

[Algorithm] 요격 시스템 #242

@hwangJi-dev

Description

@hwangJi-dev

https://school.programmers.co.kr/learn/courses/30/lessons/181188

import Foundation

func solution(_ targets:[[Int]]) -> Int {
    var targets = targets.sorted(by: { $0[0] < $1[0] })
    let f = targets.removeFirst()
    var queue: [(Int, Int)] = [(f[0], f[1])]
    var ans = 1
    
    for t in targets {
        if let q = queue.last {
            if q.1 > t[0] {
                if q.1 > t[1] {
                    queue[queue.count - 1].1 = t[1]
                }
            } else {
                queue.append((t[0], t[1]))
                ans += 1
            }
        }
    }
    
    return ans
}

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions