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
// thanks dude | |
// https://medium.com/@dushyant_db/setting-up-a-container-view-using-interface-builder-and-via-code-7ac1a7f0a0d6 | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
guard let childVC = self.storyboard?.instantiateViewController(withIdentifier: "ChildViewController") as? ChildViewController else { | |
return | |
} | |
addChildViewController(childVC) |
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
// thanks dude | |
// https://medium.com/@dushyant_db/setting-up-a-container-view-using-interface-builder-and-via-code-7ac1a7f0a0d6 | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
guard let childVC = self.storyboard?.instantiateViewController(withIdentifier: "ChildViewController") as? ChildViewController else { | |
return | |
} | |
addChildViewController(childVC) |
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
public class ListNode { | |
public var val: Int | |
public var next: ListNode? | |
public init(_ val: Int) { | |
self.val = val | |
self.next = nil | |
} | |
convenience init?(withArray array: [Int]) { | |
guard let firstVal = array.first else { return nil } |
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://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmAutoreleasePools.html | |
– (id)findMatchingObject:(id)anObject { | |
id match; | |
while (match == nil) { | |
@autoreleasepool { | |
/* Do a search that creates a lot of temporary objects. */ | |
match = [self expensiveSearchForObject:anObject]; |
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
func hasCycle(head: ListNode) -> Bool { | |
while let hareNext = hare.next?.next, let tortoiseNext = tortoise.next { | |
hare = hareNext | |
tortoise = tortoiseNext | |
if hare.val == tortoise.val { | |
return true | |
} | |
} | |
return false | |
} |
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
// assuming nodes have no duplicate values | |
var head = ListNode(5) | |
head.next = ListNode(7) | |
let secondNode = head.next | |
head.next?.next = ListNode(8) | |
head.next?.next?.next = ListNode(12) | |
head.next?.next?.next?.next = secondNode | |
var tortoise = head | |
var hare = head |
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
typedef struct node { | |
int val; | |
struct node * next; | |
} node_t; |
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
let head = ListNode(1) | |
head.next = ListNode(5) | |
head.next?.next = ListNode(42) | |
var runner = head | |
while let nextNode = runner.next { | |
runner = nextNode | |
} |
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 Node: | |
def __init__(self, dataval=None): | |
self.dataval = dataval | |
self.nextval = None |
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
public class LinkedList { | |
public var head: ListNode? | |
public var tail: ListNode? | |
public init() {} | |
public var isEmpty: Bool { | |
return head == nil | |
} | |