Skip to content

Instantly share code, notes, and snippets.

@taixingbi
taixingbi / *backtracking.py
Last active July 1, 2019 14:29
backtracking
Combination.py
https://leetcode.com/problemset/all/?search=Combination%20Sum
candidates without duplicates: 39 /
78 sub sets / 254. Factor Combinations
candidates with duplicates: 40 / 267. Palindrome Permutation II
combinations of k numbers: 216
output number of possible combinations: 377
others: 10. Regular Expression Matching / 294. Flip Game II / 291. Word Pattern II / 51. N-Queens /52. N-Queens II / 351. Android Unlock Patterns
@taixingbi
taixingbi / *SQL
Last active October 18, 2018 12:21
SQL
Structured Query Language(SQL)
*basic
. JOIN
FROM table1 JOIN table2 ON table1.col= table1.col
INNER: at least one match of rows
LEFT: match left table rows
RIGHT: match right table rows
FULL: matching rows in both tables
@taixingbi
taixingbi / * statistic
Last active October 14, 2018 12:27
data_science
1. Correlation
https://en.wikipedia.org/wiki/Correlation_coefficient
+1 strongest possible agreement
0 two varaible are independent
−1 strongest possible disagreement
r(x,y)= cov(x,y)/(var(x)*var(y))**.5
---cov(x,y)= E( (x-u)(y-u) )
---var(x) var= (E(x-u)**2 )
Depth
1 maximun depth: 104
104. Maximum Depth of Binary Tree
https://leetcode.com/problems/maximum-depth-of-binary-tree/description/
class Solution {
public int maxDepth(TreeNode root) {
//O(N)
if(root==null) return 0;
@taixingbi
taixingbi / *tree.py
Last active July 28, 2018 15:51
Tree
merge: 617
trim: 669
617. Merge Two Binary Trees
https://leetcode.com/problems/merge-two-binary-trees/description/
Example 1:
Input:
Tree 1 Tree 2
1 2
Level Order Traversal: 102 / 107 / 637
/582
102. Binary Tree Level Order Traversal
https://leetcode.com/problems/binary-tree-level-order-traversal/description/
Given binary tree [3,9,20,null,null,15,7],
3
/ \
9 20
/ \
@taixingbi
taixingbi / *HashMap.java
Last active March 22, 2019 00:55
hash table
1. Separate chaining
linked lists of values
* search time complexity: logn
2. Open addressing
Insert(k): Keep probing until an empty slot is found. Once an empty slot is found, insert k.
Search(k): Keep probing until slot’s key doesn’t become equal to k or an empty slot is reached.
* linear probing
973. K Closest Points to Origin
https://leetcode.com/problems/k-closest-points-to-origin/
We have a list of points on the plane. Find the K closest points to the origin (0, 0).
(Here, the distance between two points on a plane is the Euclidean distance.)
You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in.)
Example 1:
Input: points = [[1,3],[-2,2]], K = 1
Output: [[-2,2]]
Explanation:
The distance between (1, 3) and the origin is sqrt(10).
237. Delete Node in a Linked List
https://leetcode.com/problems/delete-node-in-a-linked-list/description/
class Solution(object):
def deleteNode(self, node):
"""
:type node: ListNode
:rtype: void Do not return anything, modify node in-place instead.
"""
if not node: return
node.val= node.next.val
@taixingbi
taixingbi / *dp.java
Last active May 23, 2019 02:55
greedy
516. Longest Palindromic Subsequence
https://leetcode.com/problems/longest-palindromic-subsequence/
https://www.youtube.com/watch?v=v8irqkTcJ6s
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000.
Example 1:
Input:
"bbbab"
Output:
4
One possible longest palindromic subsequence is "bbbb".