This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func get_all_shortest_transformation_sequences(start_word: String, target_word: String, words: [String]) -> [[String]] { | |
| var result: [[String]] = [] | |
| var found = false | |
| var level = 0 | |
| let words = Set(words) | |
| var slate: [String] = [] | |
| var parent: [String: Set<String>] = [:] | |
| var visited: Set<String> = [] | |
| var levels: [String: Int] = [:] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| func accountsMerge(_ accounts: [[String]]) -> [[String]] { | |
| var accounts: [Account] = accounts.map { | |
| var account = Account(name: $0.first!) | |
| for i in 1 ..< $0.count { | |
| account.emails.insert($0[i]) | |
| } | |
| return account | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Program { | |
| class BST { | |
| var value: Int | |
| var left: BST? | |
| var right: BST? | |
| init(value: Int) { | |
| self.value = value | |
| left = nil | |
| right = nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Move zeros to end of array in place. | |
| Brute force | |
| Loop through elements n times | |
| When 0 found | |
| Bubble up 0 to end, perform swaps until swap performed with last element | |
| O(n^2) time | O(1) space | |
| Loop through elements n times |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // GameScene.swift | |
| // project11 | |
| // | |
| // Created by David Inga on 10/23/20. | |
| // | |
| import SpriteKit | |
| class GameScene: SKScene { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func depthFirstSearch(from start: Vertex<String>, | |
| to end: Vertex<String>, | |
| in graph: GraphOP<String> ) -> Stack<Vertex<String>> { | |
| var stack = Stack<Vertex<String>>() | |
| var visited = Set<Vertex<String>>() | |
| stack.push(start) | |
| visited.insert(start) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct HashTable<Key: Hashable, Value> { | |
| private typealias Element = (key: Key, value: Value) | |
| private typealias List = LinkedList<Element> | |
| private var table: [List] | |
| init(size: Int) { | |
| table = Array<List>() | |
| for _ in 0..<size { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public struct GraphAL<Element: Hashable> { | |
| var adjList = [Element: GraphNode<Element>]() | |
| public mutating func addVertex(_ name: Element) { | |
| adjList[name] = GraphNode(name) | |
| } | |
| @discardableResult public mutating func addEdge(from source: Element, to destination: Element) -> Bool { | |
| guard adjList[source] != nil, adjList[destination] != nil | |
| else { return false } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public struct GraphAM { | |
| private var adjMatrix = [[Int?]]() | |
| private var numberOfVertices: Int { | |
| return adjMatrix.count | |
| } | |
| init(numberOfVertices: Int) { | |
| adjMatrix = Array(repeating: Array(repeating: nil, count: numberOfVertices), count: numberOfVertices) | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public enum EdgeType { | |
| case directed, undirected | |
| } | |
| public struct Edge<Element: Hashable> { | |
| var source: Vertex<Element> | |
| var destination: Vertex<Element> | |
| var weight: Double? | |
| } |
NewerOlder