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
matrix = [ | |
[1,2,3], | |
[4,5,6] | |
] | |
def transpose(matrix: list) -> list: | |
if len(matrix) == 0: | |
return [] | |
rows, cols = len(matrix), len(matrix[0]) | |
new_matrix = [[None] * rows for i in range(cols)] |
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
def reverse_int(n: int) -> int: | |
num, reverse_num, size_of_num = n, 0, -1 | |
copy = num | |
while copy >= 1: | |
copy //= 10 | |
size_of_num += 1 | |
while num >= 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
""" | |
This short script allows to draw a asteriks pyramid | |
in any direction desired. 'Left' is the default direction. | |
A 'middle' pyramid has n steps with (n*2-1) asteriks. | |
""" | |
def draw_pyramid(steps: int, direction: str = "left") -> None: | |
possible_directions = set(["left", "right", "middle"]) |
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
#!/bin/bash | |
sudo apt update | |
sudo apt upgrade | |
sudo apt autoremove | |
sudo apt autoclean |
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
#!/bin/bash | |
for d in ./*/ | |
do (cd "$d" && | |
if [[ -d .git ]]; then | |
echo "Pulling from $d" | |
git pull | |
fi; | |
) | |
done; |
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 source and a destination, let us | |
find the path (if existing) between the two. | |
""" | |
company = { | |
"Bill":"Ada", | |
"Monty":"Alan", | |
"Ada":"Bob", | |
"John":"Linus", |
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
""" | |
Stack and Queue being implemented with Python List. | |
Both structures follow the design below: | |
Bottom -> [...] -> Top. | |
""" | |
def dequeue(array: list) -> int: | |
return array.pop() |
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 program will find the element at the exact | |
middle of any columns (N) x rows (Y < N) matrix where | |
the number of columns and rows are odd. | |
# xxxxx | # xxxxx | # xxxx | # xxx | |
# xx(x)xx | # xxxxx | # xxxx | # x(x)x | |
# xxxxx | # No middle | # xxxx # No middle | # xxx | |
""" |
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
""" | |
Assume we have defined a BST class: | |
class BST(object): | |
class __Node(object): | |
def __init__(self, data, right=None, left=None): | |
self.data = data | |
self.right = right | |
self.left = left | |
def __init__(self, root=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
import sys | |
class LinkedList(object): | |
class __Node(object): | |
def __init__(self, val, next=None): | |
self.val = val | |
self.next = next | |
def setNext(self, newNext): | |
self.next = newNext |
NewerOlder