Skip to content

Instantly share code, notes, and snippets.

View tolinwei's full-sized avatar

Wei Lin tolinwei

  • Facebook
  • Cambridge, MA
View GitHub Profile
public int countSquare ( boolean[][] ver , boolean[][] hor ) {
if ( ver == null || hor == null || ver.length == 0 || ver[0].length == 0 || hor.length == 0 || hor[0].length == 0 ){
return 0;
}
int[][] dpV = new int[ ver.length ][ ver[0].length ];
int[][] dpH = new int[ hor.length ][ hor[0].length ];
int res = 0;
for ( int j = 0; j < dpV[0].length; ++j) {
public int countSquare ( boolean[][] ver , boolean[][] hor ) {
if ( ver == null || hor == null || ver.length == 0 || ver[0].length == 0 || hor.length == 0 || hor[0].length == 0 ){
return 0;
}
int[][] dpV = new int[ ver.length ][ ver[0].length ];
int[][] dpH = new int[ hor.length ][ hor[0].length ];
int res = 0;
for ( int j = 0; j < dpV[0].length; ++j) {
public int countSquare ( boolean[][] ver , boolean[][] hor ) {
if ( ver == null || hor == null || ver.length == 0 || ver[0].length == 0 || hor.length == 0 || hor[0].length == 0 ){
return 0;
}
int[][] dpV = new int[ ver.length ][ ver[0].length ];
int[][] dpH = new int[ hor.length ][ hor[0].length ];
int res = 0;
for ( int j = 0; j < dpV[0].length; ++j) {
@tolinwei
tolinwei / SerializingBinaryTree.java
Created October 16, 2016 22:42 — forked from bittib/SerializingBinaryTree.java
Serialize and Deserialize a Binary Tree (pre order).
class TreeNode{
int val;
TreeNode left, right;
TreeNode(int val){
this.val = val;
}
}
public String serialize(TreeNode root){
StringBuilder sb = new StringBuilder();
@tolinwei
tolinwei / Bit
Created October 14, 2016 06:31
Bit
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.InterruptedIOException;
import java.util.*;
public class Main {
public static void main(String[] args) {
System.out.println(getIntegerComplement(50));
System.out.println(getIntegerComplement(100));
public class DecodeWays {
/**
* @param s a string, encoded message
* @return an integer, the number of ways decoding
*/
private int res = 0;
public int numDecodings(String s) {
// Write your code here
if (s == null || s.length() == 0) {
return 0;
public class Solution { // extends LinkedHashMap<Integer, Integer> {
// Map<Integer, Integer> map;
// LinkedList<Integer> map;
int capacity;
LinkedHashMap<Integer, Integer> cache;
// @param capacity, an integer
public Solution(final int capacity) { // local variable capacity is accessed from within inner class;
public class LRUCache extends LinkedHashMap<integer, string=""> {
private int cacheSize;
public LRUCache(int size) {
super(size, 0.75f, true);
this.cacheSize = size;
}
@Override
protected boolean removeEldestEntry(
/**
* Created by linwei on 9/22/16.
*/
public class FindKthSmallest {
/*
* Example:
* 1,2,3,4 and 3,4,5,6,7 k=5, return 4;
* 1,2,3,4 and 3,4,5,6,7 k=2, return 2;
*/
public int find(int[] a, int[] b, int k) {
/**
* Created by linwei on 9/20/16.
*/
public class PivotNumber {
/* Test case:
3 4 5 2 (6) 7 8 9 return 6's index 4
4 2 6 (5) 7 8 9 return 5's index 3
4 2 6 5 3 9 return -1
*/
public int get(int[] array) {