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 LinkedList(object): | |
class __Node(object): | |
def __init__(self, val, next=None): | |
self.val = val | |
self.next = next | |
def __init__(self, head): | |
self.head = LinkedList.__Node(head) | |
def add(self, val): |
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
""" | |
Given a N x N matrix, let us extract the rows and columns. | |
This function takes a matrix as parameter and returns a | |
tuple of rows and columns. Both rows and columns are also matrices. (lists of lists) | |
NOTE: matrix passed in as parameter must have N rows and N columns for this algorithm | |
to work. | |
""" |
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
""" | |
This pattern guesses and checks if there are any even numbers in a given array | |
and returns True or False. | |
""" | |
def guess_and_check(array: list) -> bool: | |
if len(array) == 0: | |
return False | |
found = 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
""" | |
Implementation of a Stack (FILO) Data Structure | |
using a Linked List. | |
""" | |
class LinkedList(object): | |
class __Node(object): | |
def __init__(self, val): | |
self.val = val |
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's assume we have a Binary Tree. | |
class BinaryTree(object): | |
def __init__(self, val): | |
self.val = val | |
self.right = None | |
self.left = None | |
I understand there may be some breaking of data encapsulation below. |
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
""" | |
Both binary search functions implemented below assume the element being searched | |
is an integer but this can certainly be done with strings as well. | |
""" | |
# Iterative Binary Search | |
def iterative_binary_search(arr: list, element: int) -> bool: | |
start = 0 | |
end = len(arr) - 1 |
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
from flask import Flask | |
app = Flask(__name__) | |
@app.route("/") | |
def index(): | |
return "You have reached the index route!" | |
if __name__ == "__main__": | |
app.run(debug=True) |
NewerOlder