Swift💯 BitSet DFS/BFS
BitSet DFS (accepted answer)BitSetref:https://swift-collections/1.1.0/documentation/bitcollections/bitsetBitSet BFS (accepted answer)
**BitSet DFS (accepted answer)**
```
class FindElements {
  var set = BitSet()
  init(_ root: TreeNode?) {
    func dfs(_ node: TreeNode?, _ val:Int) {
      guard let node else { return }
      set.insert(val)
      dfs(node.left, val*2 + 1)
      dfs(node.right, val*2 + 2)
    }
    dfs(root, 0)
  }
  func find(_ target: Int) -> Bool {
    set.contains(target)
  }
}
```
`BitSet` ref: [https://swift-collections/1.1.0/documentation/bitcollections/bitset](https://swiftpackageindex.com/apple/swift-collections/1.1.0/documentation/bitcollections/bitset)

**BitSet BFS (accepted answer)**
```
class FindElements {
  var set = BitSet()

  init(_ root: TreeNode?) {
    guard let root else { return }
    root.val = 0
    set = BitSet(
      sequence(
        first: [root],
        next: {prev in
          let next = prev.flatMap { node in
            node.left?.val = node.val*2 + 1
            node.right?.val = node.val*2 + 2
            return [node.left, node.right].compactMap{$0}
          }
          return next.isEmpty ? nil : next
        }
      )
      .flatMap{$0.map(\.val)}
    )
  }
    
  func find(_ target: Int) -> Bool {
    set.contains(target)
  }
}
```
['Swift']