Skip to content

Instantly share code, notes, and snippets.

View DrynnBavis's full-sized avatar

Brynn Davis DrynnBavis

View GitHub Profile
class Solution {
private:
int fact(int n) {
int ans = 1;
for(int i = 1; i <= n; ++i) ans *= i;
return ans;
}
public:
vector<vector<int>> permute(vector<int>& nums) {
const int n = nums.size();
@DrynnBavis
DrynnBavis / Pascal's Pyramid
Created February 2, 2019 00:31
c++ solution to Pascal Pyramid
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> result;
if(!numRows) return {};
result.push_back({1});
for(int i = 0; i < numRows-1; i++){
vector<int> row;
vector<int> prevRow = result.back();
for(int k = 0; k < prevRow.size(); k++){
@DrynnBavis
DrynnBavis / gist:3fce4747215a5177ce777007c9af91c1
Created January 12, 2019 16:35
Iterative DFS for binary tree
"""
# Definition for a Node.
class Node(object):
def __init__(self, val, children):
self.val = val
self.children = children
"""
class Solution(object):
def preorder(self, root):
"""
@DrynnBavis
DrynnBavis / GetLCAFromBST.py
Created December 6, 2018 06:43
Returns the lowest common ancestor in a BST
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def lowestCommonAncestor(self, root, p, q):
"""
@DrynnBavis
DrynnBavis / LC_PalindromeSingleLinkedList.py
Last active December 6, 2018 06:03
returns true if linked list of nums is a palindrome
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def isPalindrome(self, head):
@DrynnBavis
DrynnBavis / HanoiTowers
Last active December 2, 2018 04:25
A recursive solition to the Hanoi Towers problem
def solve_towers(n_disks, source, dest, helper):
if n_disks == 0:
return
solve_towers(n_disks-1, source, helper, dest)
move_disks(n_disks-1, source, dest)
solve_towers(n_disks-1, helper, dest, source)
def move_disks(n_disks, source, dest):
print("Moving disk {} from {} -> {}".format(n_disks, source, dest))
execute pathogen#infect()
syntax on
filetype plugin indent on
set cursorline
set number
set noerrorbells
set title
let g:solarized_termcolors=16
set t_Co=16
@DrynnBavis
DrynnBavis / Circular Queue
Created September 5, 2018 18:11
Python3 Circular Queue Class
class circ_queue(object):
"""docstring for circ_queue."""
queue = []
head = 0
tail = 0
len = 0
def __init__(self, max_len = 8):
super(circ_queue, self).__init__()
self.queue = [None] * max_len
self.len = max_len
@DrynnBavis
DrynnBavis / mnist.py
Last active March 1, 2018 04:39
A Python 3 friendly generator object for reading in MNIST training data.
import os
import struct
import numpy as np
"""
Python3 friendly version of the following work:
https://gist.github.com/akesling/5358964
"""
def read(dataset = "training", path = "Data"):