Skip to content

Instantly share code, notes, and snippets.

View makeapp007's full-sized avatar

Yonghao Liu makeapp007

View GitHub Profile
@makeapp007
makeapp007 / lc144.py
Created January 13, 2022 20:45
Leetcode 144. Binary Tree Preorder Traversal
recursion
class Solution:
def preorderTraversal(self, root: TreeNode) -> List[int]:
if not root:
return []
ret = []
def dfs(node):
if not node:
return
@makeapp007
makeapp007 / lc701.py
Created January 12, 2022 15:39
Leetcode 701. Insert into a Binary Search Tree
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
@makeapp007
makeapp007 / lc1022.py
Last active January 11, 2022 18:03
1022. Sum of Root To Leaf Binary Numbers
# 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:
@makeapp007
makeapp007 / lc67.py
Created January 10, 2022 21:38
67. Add Binary
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:]
@makeapp007
makeapp007 / lc1041.py
Created January 10, 2022 02:32
leetcode1041. Robot Bounded In Circle
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]
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: flaskapp
labels:
deployment: flaskapp
spec:
replicas: 1
selector:
matchLabels:
@makeapp007
makeapp007 / py
Created August 24, 2018 18:54
python code example
# -*- 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
# 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