This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TreeNode{ | |
int val; | |
TreeNode left, right; | |
TreeNode(int val){ | |
this.val = val; | |
} | |
} | |
public String serialize(TreeNode root){ | |
StringBuilder sb = new StringBuilder(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { |