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
# File: FindDuplicate.py | |
# Author: Keith Schwarz ([email protected]) | |
# | |
# An algorithm for solving the following (classic) hard interview problem: | |
# | |
# "You are given an array of integers of length n, where each element ranges | |
# from 0 to n - 2, inclusive. Prove that at least one duplicate element must | |
# exist, and give an O(n)-time, O(1)-space algorithm for finding some | |
# duplicated element. You must not modify the array elements during this | |
# process." |
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
# bash/zsh completion support for core Git. | |
# | |
# Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]> | |
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/). | |
# Distributed under the GNU General Public License, version 2.0. | |
# | |
# The contained completion routines provide support for completing: | |
# | |
# *) local and remote branch names | |
# *) local and remote tag names |
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
struct Matrix { | |
let rows: Int | |
let columns: Int | |
var elements: [[Int]] | |
// MARK: - Constructors | |
private init(rows: Int, columns: Int) { | |
self.rows = rows | |
self.columns = columns | |
elements = Array(repeating: Array(repeating: 0, count: columns), count: rows) |
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://medium.com/swlh/fibonacci-swift-playground-f56d1ff3ea99 | |
// recursive approach | |
// time: O(n^2) | |
// space: O(n^2) | |
func fib1(_ n: Int) -> Int { | |
guard n > 2 else { return n } | |
return fib(n-1) + fib(n-2) | |
} | |
//////////////////////////////////////////////// |