This file contains hidden or 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
| #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 |
This file contains hidden or 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
| #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 |
This file contains hidden or 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
| #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 |
This file contains hidden or 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
| #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 |
This file contains hidden or 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
| """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 |
This file contains hidden or 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
| #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 |