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 flatten_dictionary(dictionary): | |
flattened = {} | |
flattened = flatten_helper("", dictionary, flattened) | |
return flattened | |
def flatten_helper(initKey, dictionary, flattened): | |
for k, v in dictionary: | |
if not isInstance(v, dict): | |
if initKey is None or initKey == "": |
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
from collections import deque | |
class Solution: | |
def wallsAndGates(self, rooms: List[List[int]]) -> None: | |
""" | |
Do not return anything, modify rooms in-place instead. | |
""" | |
if not rooms: | |
return 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
class Solution: | |
def permute(self, nums: List[int]) -> List[List[int]]: | |
list = [] | |
tempList = [] | |
def backtrack(list, tempList, nums): | |
if len(tempList) == len(nums): | |
list.append(tempList) | |
else: |
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/python3 | |
import math | |
import os | |
import random | |
import re | |
import sys | |
# Complete the candies function below. | |
def candies(n, arr): |
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
class Solution { | |
static int WHITE = 0, GRAY = 1, BLACK = 2; | |
private int V; | |
private LinkedList<Integer> adj[]; | |
Graph(int v) { | |
V = v; |
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
from collections import defaultdict | |
class Solution: | |
def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool: | |
gra = Graph(len(prerequisites)) | |
for preReq in prerequisites: | |
gra.addEdge(preReq[0], preReq[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
func canFinish(numCourses int, prerequisites [][]int) bool { | |
next := Next(numCourses, prerequisites) | |
pres := Pres(next) | |
return check(next, pres, numCourses) | |
} | |
func Next(n int, prereq [][]int) [][]int { | |
next := make([][]int,n) | |
for _, pair := range prereq { |
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 calc_drone_min_energy(route): | |
if not route: | |
return 0 | |
initialz = route[0][2] | |
greatestz = initialz | |
for z in range(1, len(route), 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
class Solution: | |
def kClosest(self, points: List[List[int]], K: int) -> List[List[int]]: | |
""" | |
in: List, K | |
out List | |
Time: NLogN due to sorting | |
Space: N due to dictionary | |
""" |
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
class Solution: | |
def repeatedNTimes(self, A: List[int]) -> int: | |
for i in range(len(A)): | |
if A.count(A[i]) == len(A)//2: | |
return A[i] | |
""" |