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
recursion | |
class Solution: | |
def preorderTraversal(self, root: TreeNode) -> List[int]: | |
if not root: | |
return [] | |
ret = [] | |
def dfs(node): | |
if not node: | |
return |
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 insertIntoBST(self, root: TreeNode, val: int) -> TreeNode: | |
if not root: | |
return TreeNode(val) | |
if val > root.val: | |
# insert into the right subtree | |
root.right = self.insertIntoBST(root.right, val) | |
else: | |
# insert into the left subtree |
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
# Thought process: https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers/discuss/1683424/Python3-DFS-solution | |
# | |
# Definition for a binary tree node. | |
# class TreeNode: | |
# def __init__(self, val=0, left=None, right=None): | |
# self.val = val | |
# self.left = left | |
# self.right = right | |
class Solution: | |
def sumRootToLeaf(self, root: Optional[TreeNode]) -> int: |
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 addBinary(self, a: str, b: str) -> str: | |
m, n = int(a, 2), int(b, 2) | |
while n: | |
ans = m ^ n | |
carry = (m & n) << 1 | |
m = ans | |
n = carry | |
return bin(m)[2:] |
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 isRobotBounded(self, instructions: str) -> bool: | |
directions = { | |
'north': (0, 1), 'south': (0, -1), 'east': (1, 0), 'west': (-1, 0) | |
} | |
direction = 'north' | |
row = col = 0 | |
for i in instructions: | |
if i == 'G': | |
x, y = directions[direction] |
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
apiVersion: apps/v1beta2 | |
kind: Deployment | |
metadata: | |
name: flaskapp | |
labels: | |
deployment: flaskapp | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: |
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
# -*- coding: utf-8 -*- | |
#from scrapy_redis.spiders import RedisSpider | |
from invest.items import investLoader | |
from scrapy.spiders import BaseSpider | |
from redis import Redis | |
#to use self.log | |
from scrapy import log | |
from time import sleep |
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
# install dependencies | |
sudo apt-get update | |
sudo apt-get install -y build-essential | |
sudo apt-get install -y cmake | |
sudo apt-get install -y libgtk2.0-dev | |
sudo apt-get install -y pkg-config | |
sudo apt-get install -y python-numpy python-dev | |
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev | |
sudo apt-get install -y libjpeg-dev libpng-dev libtiff-dev libjasper-dev | |