This file contains 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 ViewController: UIViewController { | |
@IBOutlet weak var textField: UITextField! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view. | |
let datePicker = UIDatePicker() |
This file contains 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
// 1 3 800 | |
// 1 2 500 | |
// 2 3 500 | |
// 1 70 | |
// 2 40 | |
// 1 3 | |
public static class Station { | |
int city; | |
int price; | |
int capacity; |
This file contains 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
// https://leetcode.com/problems/add-and-search-word-data-structure-design/ | |
// For add(): | |
// Time: O(n), Space: O(n) | |
// For search(): | |
// Time: O(n), Space: O(n) because of the recursive calls | |
// Where there are wildcards: | |
// The absolute worst case we can have 26 children at each node, traversing through all nodes with DFS will take 26^n (n nodes, each nodes have 26 children/characters). 26^n is technically 2^n. Therefore, | |
// Time: O(2^n), Space: O(n) because we only have at max n calls on the stack at any given time. | |
// or O(m) where m is the total number of characters on the trie. |
This file contains 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
// https://leetcode.com/problems/maximum-depth-of-binary-tree/ | |
// Recursive | |
// Time: O(n), Space: O(n) | |
func maxDepth(_ root: TreeNode?) -> Int { | |
guard let root = root else { return 0 } | |
return 1 + max(maxDepth(root.left), maxDepth(root.right)) | |
} | |
// Iterative | |
// Time: O(n), Space: O(n) |
This file contains 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
// https://leetcode.com/problems/subsets/ | |
// Approach 1: Cascading | |
// Time: O(n*2^n), Space: O(n*2^n) | |
func subsets(_ nums: [Int]) -> [[Int]] { | |
var result = [[Int]]() | |
result.append([]) | |
for num in nums { | |
for currSet in result { | |
result.append(currSet + [num]) | |
} |
This file contains 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
// https://leetcode.com/problems/binary-tree-maximum-path-sum/ | |
// O(n), Space O(n) | |
var globalMax = Int.min | |
func maxPathSum(_ root: TreeNode?) -> Int { | |
maxPath(root) | |
return globalMax | |
} | |
func maxPath(_ root: TreeNode?) -> Int { | |
guard let root = root else { return 0 } |
This file contains 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
// ------------------MEDIUM------------------ // | |
// https://leetcode.com/problems/clone-graph/ | |
// DFS | |
// Time: O(n), Space: O(n) | |
func cloneGraph(_ node: Node?) -> Node? { | |
var dict = [Int : Node]() | |
return cloneNode(node, &dict) | |
} |
This file contains 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
// https://leetcode.com/problems/top-k-frequent-elements/ | |
// O(n), O(n) | |
func topKFrequent(_ nums: [Int], _ k: Int) -> [Int] { | |
var freqDict = [Int : Int]() | |
var bucket = [Int : [Int]]() | |
var result = [Int]() | |
var topFreq = 0 | |
// O(n) | |
for num in nums { |
This file contains 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
// https://leetcode.com/problems/number-of-islands/ | |
// Time: n*m, Space 1 | |
func numIslands(_ grid: [[Character]]) -> Int { | |
var gridCopy = grid | |
var islandCount = 0 | |
for i in 0..<gridCopy.count { | |
for j in 0..<gridCopy[0].count { | |
if gridCopy[i][j] != "0" { | |
markAdjacentLands(i, j, inGrid: &gridCopy) |
This file contains 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
// Toaster | |
class Bread { | |
var cookedTime: Double = 0.0 | |
} | |
enum TrayLevel { | |
case down | |
case up | |
} |
NewerOlder