Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions linked-list-cycle/delight010.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public class ListNode {
public var val: Int
public var next: ListNode?
public init(_ val: Int) {
self.val = val
self.next = nil
}
}


class Solution {
// Time O(n)
// Space O(1)
func hasCycle(_ head: ListNode?) -> Bool {
var slow: ListNode? = head
var fast: ListNode? = head

while fast != nil && fast?.next != nil {
slow = slow?.next
fast = fast?.next?.next

if slow === fast {
return true
}
}
return false
}
}

18 changes: 18 additions & 0 deletions sum-of-two-integers/delight010.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
// Time O(log n)
// Space O(1)
func getSum(_ a: Int, _ b: Int) -> Int {
var a = a
var b = b

while b != 0 {
var sum = a ^ b
var carry = (a & b) << 1
a = sum
b = carry
}

return a
}
}