Skip to content

Instantly share code, notes, and snippets.

View bobfang1992's full-sized avatar
🏠
Working from home

Bob Fang bobfang1992

🏠
Working from home
View GitHub Profile
@bobfang1992
bobfang1992 / threadapi.json
Created March 6, 2021 22:51
threadapi.json
// 20210306225038
// https://duibiao-1298595392.ap-east-1.elb.amazonaws.com/api/threads/?category=6
{
"results": [
{
"id": 66,
"category": 6,
"title": "How to create a time_point object with year month day?",
"replies": 0,
@bobfang1992
bobfang1992 / word_break.java
Last active January 10, 2021 00:42
mock_interview_3
/*
s = "applepenapple" dictionary = ["apple", "pen"]
s = "apple" + "pen" + "apple"
return True
s = "appplepearapple" dictionary = ["apple", "pen"]
return False
@bobfang1992
bobfang1992 / mock_interview_2.txt
Last active January 5, 2021 14:29
mock_interview_2
//
//Given two sequences pushed and popped with distinct values,
//return true if and only if this could have been the result of a sequence of push and pop operations on an initially empty stack.
//Example 1:
//Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,1]
//Output: true
//Explanation: We might do the following sequence:
@bobfang1992
bobfang1992 / 1265.py
Created January 2, 2021 22:16
Mock Interveiw 1--1265. Print Immutable Linked List in Reverse
// Print Immutable Linked List in Reverse
// immutable linked list, print out all values of each node in reverse
// APIs:
// ImmutableListNode: An interface of immutable linked list, you are given the head of the list.
// You need to use the following functions to access the linked list (you can't access the ImmutableListNode directly):
// ImmutableListNode.printValue(): Print value of the current node.
// ImmutableListNode.getNext(): Return the next node.
# getNext() -> ImmutableListNode or None
@bobfang1992
bobfang1992 / 1379.py
Created January 2, 2021 11:10
Leetcode 1379
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def getTargetCopy(self, original: TreeNode, cloned: TreeNode, target: TreeNode) -> TreeNode:
val = target.val
@bobfang1992
bobfang1992 / 84.py
Created December 31, 2020 16:44
Leetcode 84
class Solution:
def largestRectangleArea(self, heights: List[int]) -> int:
stack = [-1]
result = 0
heights.append(0)
for i in range(len(heights)):
while stack and heights[stack[-1]] > heights[i]:
h = heights[stack.pop()]
w = i - stack[-1] - 1
@bobfang1992
bobfang1992 / 289.py
Created December 30, 2020 17:07
Leetcode 289
class Solution:
def gameOfLife(self, board: List[List[int]]) -> None:
"""
Do not return anything, modify board in-place instead.
"""
m = len(board)
if m == 0:
return
n = len(board[0])
from fastapi import FastAPI
import uuid
app = FastAPI()
COM_API_OBJECT = {}
@app.get("/create")
async def create():
@bobfang1992
bobfang1992 / clear_db.sql
Created August 13, 2020 08:59
Delete every table in PG
DO $$ DECLARE
r RECORD;
BEGIN
FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP
EXECUTE 'DROP TABLE ' || quote_ident(r.tablename) || ' CASCADE';
END LOOP;
END $$;

key - value mapping

{
  "name": "Bob"
  "age": 28,
  "sex": "male"
}