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
class Solution: | |
def make_bst(self, nums, start, end): | |
if end < start: | |
return None | |
mid = (start + end) // 2 | |
n = TreeNode(nums[mid]) | |
n.left = self.make_bst(nums, start, mid - 1) | |
n.right = self.make_bst(nums, mid + 1, end) | |
return n |
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
def one_edit(a, b): | |
edits = 0 | |
if a == b: | |
return True | |
elif len(a) == len(b): | |
for x, y in zip(a, b): | |
if x != y: | |
edits += 1 | |
if edits > 1: | |
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
def mergeTwoLists(self, l1, l2): | |
""" | |
:type l1: ListNode | |
:type l2: ListNode | |
:rtype: ListNode | |
""" | |
if l1 is not None and l2 is not None: | |
if l1.val < l2.val: | |
head = ListNode(l1.val) | |
tail = head |
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
def hasCycle(self, head): | |
""" | |
:type head: ListNode | |
:rtype: bool | |
""" | |
if head is not None: | |
nodes = [] | |
nodes.append(head) | |
current = head | |
while current.next is not None: |
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
import numpy as np | |
import pandas as pd | |
class AliciaKNN: | |
def __init__(self, df, class_col_name): | |
self.df = df | |
self.class_col_name = class_col_name | |
@property |
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
from collections import deque | |
class Solution: | |
def isValid(self, s: 'str') -> 'bool': | |
stack = deque() | |
for char in s: | |
if char == '(': | |
stack.append(char) | |
elif char == ')': | |
if len(stack) == 0 or stack.pop() != '(': |
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
from math import floor | |
def binary_search(target, lst): | |
""" | |
:param target: The item to find. | |
:param lst: The sorted list to look through | |
:return: -1 if the target is not found. Index if found otherwise | |
""" |
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
from collections import deque | |
class GraphNode: | |
def __init__(self, id): | |
self.id = id | |
self.neighbors = [] | |
def bfs_search(root, target_id): | |
if root is None: |
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
class Solution: | |
def intersect(self, nums1, nums2): | |
""" | |
:type nums1: List[int] | |
:type nums2: List[int] | |
:rtype: List[int] | |
""" | |
nums1_count = {} | |
for x in nums1: | |
if x in nums1_count: |
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
/*** CODE ***/ | |
class SelectionSort { | |
int[] sort(int[] arr) { | |
// We start i=0 because j = i + 1. i is always less than j. | |
// This OUTER loop moves left to right, with i marking the | |
// LEFT boundary of the UNSORTED section. | |
for (int i = 0; i < arr.length - 1; i++) { |