Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct House{
- let id : Int
- let left : Int
- let right : Int
- init(_ id: Int, _ left: Int, _ right: Int) {
- self.id = id
- self.left = left
- self.right = right
- }
- }
- func getBlock(_ arr: [House]) -> Int{
- var visited = Set<Int>()
- var count = arr.count
- for house in arr{
- if visited.contains(house.left) { count -= 1}
- if visited.contains(house.right) { count -= 1}
- visited.insert(house.id)
- }
- return count
- }
- let h3 = House(3, 2,4)
- //let h2 = House(2, 1,3)
- let h1 = House(1, 0,2)
- let h7 = House(7, 6,8)
- let arr = [h1,h3,h7]
- print(getBlock(arr))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement