Skip to content

Instantly share code, notes, and snippets.

@taixingbi
taixingbi / * html
Last active December 13, 2018 15:56
Hypertext Markup Language (HTML)
standard markup language for creating web pages and web applications.
With Cascading Style Sheets (CSS) and JavaScript,for the World Wide Web.
1. DOM
1.1 Element P, DIV, A, TABLE
class TrieNode {
char ch;
Map<Character, TrieNode> children= new HashMap<>();
boolean isWord;
}
class TrieHashMap{
TrieNode root= new TrieNode();
//O(k) k= length of word
package basic;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Stack;
import java.util.Vector;
import basic.graph.Graph;
public class graph {
@taixingbi
taixingbi / *array.py
Last active January 9, 2019 15:51
array
swap
832. Flipping an Image
https://leetcode.com/problems/flipping-an-image/description/
Input: [[1,1,0],[1,0,1],[0,0,0]]
Output: [[1,0,0],[0,1,0],[1,1,1]]
class Solution(object):
def flipAndInvertImage(self, A):
"""
@taixingbi
taixingbi / *string.py
Last active December 15, 2018 13:53
string
1. sort(key=len, reverse=True)
example
input: ["apple", "pear", "a","long", "longisland"]
output: ['longisland', 'apple', 'pear', 'long', 'a']
problem: 294
2. zip(*iterables)
words= ["apple", "pear", "he", "longisland"]
for letters in zip(*words):
for letters in zip("apple", "pear", "he", "longisland"):
@taixingbi
taixingbi / *two points.py
Last active February 4, 2019 13:05
two points
88. Merge Sorted Array
https://leetcode.com/problems/merge-sorted-array/description/
Input:
nums1 = [1,2,3,0,0,0], m = 3
nums2 = [2,5,6], n = 3
Output: [1,2,2,3,5,6]
class Solution(object):
def merge(self, nums1, m, nums2, n):
"""
@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".
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
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).
@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