Skip to content

Instantly share code, notes, and snippets.

View KellyOShaughnessy's full-sized avatar

Kelly O'Shaughnessy KellyOShaughnessy

View GitHub Profile
@KellyOShaughnessy
KellyOShaughnessy / is_unique_string_again.py
Created October 14, 2015 06:00
Determines if a string contains all unique chars without using additional data structures in python
#Soln. by Kelly O'Shaughnessy
def is_unique_again(s):
"""Returns: True if all chars in string are unique, false if else or if empty string.
Case and white space sensitive. s must be a string."""
for c in s:
if s.count(c) != 1:
return False
return True
@KellyOShaughnessy
KellyOShaughnessy / is_unique_string.py
Created October 14, 2015 05:57
Determines if a string contains all unique characters in python
#Soln. by Kelly O'Shaughnessy
def is_unique(s):
"""Returns: boolean if string has all unique chars or false if empty or nonunique chars."""
myset = set(s)
if len(myset) == len(s) and len(s) != 0:
return True
else:
return False
@KellyOShaughnessy
KellyOShaughnessy / permutation.py
Created October 14, 2015 05:50
Checks if two strings are permutations of each other; case and whitespace insensitive
#Soln. by Kelly O'Shaughnessy
def perm_string(s1,s2):
"""Returns: a boolean if s1 is a permutation of s2.
Ex: permutations of "abc" are "abc","bca","acb","bac","cba","cab"
Function also would accept: "ABC", "a C b ", "BcA", etc...
"""
#case insensitive
low1 = s1.lower()
low2 = s2.lower()
#get rid of whitespace
@KellyOShaughnessy
KellyOShaughnessy / quicksort.py
Created October 14, 2015 05:37
Quicksort Implementation in python
#Soln. by Kelly O'Shaughnessy
#quicksort
def quicksort_helper(lst,beg,end):
if (beg >= end):
return
else:
pivot_ind = beg + (end - beg)/2
pivot = lst[pivot_ind]
i=beg
@KellyOShaughnessy
KellyOShaughnessy / matrixshift.py
Last active December 7, 2017 22:01
Rotate an nxn matrix by 90 degrees in python
"""Kelly O'Shaughnessy
Rotate nxn matrix by 90 degrees"""
def rotate(matrix):
if matrix is None or len(matrix)<1:
return
else:
if len(matrix)==1:
return matrix
else:
#solution matrix
@KellyOShaughnessy
KellyOShaughnessy / queuetostack.py
Last active July 26, 2019 12:00
Implementing a stack given two queues in python
#Soln by Kelly O'Shaughnessy
#implement stack using two Queues
class QueuetoStack:
def __init__(self):
self.q1 = []
self.q2 = [] #will act as empty temp Queue
def push(self,x):
self.q1.insert(x,0) #enqueue