Skip to content

Instantly share code, notes, and snippets.

@maydayco
maydayco / gist:5745006
Created June 9, 2013 20:11
Multiply Strings
public class Solution {
public String multiply(String num1, String num2) {
// Start typing your Java solution below
// DO NOT write main() function
int adv = 0;
int[] num = new int[num1.length() + num2.length() ];
num1 = new StringBuffer(num1).reverse().toString();
num2 = new StringBuffer(num2).reverse().toString();
for (int i = 0; i < num1.length(); i++) {
for (int j = 0; j < num2.length(); j++) {
@maydayco
maydayco / gist:5732160
Last active December 18, 2015 05:19
Minimum Window Substring
public class Solution {
public String minWindow(String S, String T) {
// Start typing your Java solution below
// DO NOT write main() function
int[] num = new int[256];
int[] hasFound = new int[256];
for (int i = 0; i < T.length(); i++) {
num[T.charAt(i)]++;
}
int found = 0;
@maydayco
maydayco / gist:5731041
Created June 7, 2013 17:47
Minimum Window Substring
public class Solution {
public String minWindow(String S, String T) {
// Start typing your Java solution below
// DO NOT write main() function
HashMap<Character, LinkedList<Integer>> hash = new HashMap<Character, LinkedList<Integer>>();
HashSet<Character> set = new HashSet<Character>();
PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
int[] num = new int[256];
for (int i = 0; i < T.length(); i++) {
num[T.charAt(i)]++;
@maydayco
maydayco / gist:5730532
Created June 7, 2013 16:28
Interleaving String not clean code
public class Solution {
public boolean isInterleave(String s1, String s2, String s3) {
// Start typing your Java solution below
// DO NOT write main() function
if (s1.length() + s2.length() != s3.length())
return false;
boolean[][] sol = new boolean[s1.length() + 1][s2.length() + 1];
sol[0][0] = true;
@maydayco
maydayco / gist:5730141
Created June 7, 2013 15:32
Regular Expression Matching
public class Solution {
public boolean isMatch(String s, String p) {
// Start typing your Java solution below
// DO NOT write main() function
boolean[][] sol = new boolean[s.length() + 1][p.length() + 1];
sol[0][0] = true;
for (int i = 2; i <= p.length(); i++) {
if (p.charAt(i - 1) == '*') {
sol[0][i] = sol[0][i - 2];
}
@maydayco
maydayco / gist:5729982
Created June 7, 2013 15:12
Wildcard Matching
public class Solution {
public boolean isMatch(String s, String p) {
// Start typing your Java solution below
// DO NOT write main() function
boolean[][] sol = new boolean[2][p.length() + 1];
sol[0][0] = true;
int len = 0;
for (int i = 1; i <= p.length(); i++) {
if (p.charAt(i - 1) == '*')
sol[0][i] = sol[0][i - 1];
@maydayco
maydayco / gist:5717634
Created June 5, 2013 21:54
Insert Interval
/**
* Definition for an interval.
* public class Interval {
* int start;
* int end;
* Interval() { start = 0; end = 0; }
* Interval(int s, int e) { start = s; end = e; }
* }
*/
public class Solution {
/**
*The IncidentsCalculation calculates the incidents percentage for a given query and all the incidents.
*
* @author Xidong Liu <xliu035@gmail.com>
*/
import java.util.*;
public class IncidentsCalculation {
/**
* The IncidentsCalculationExtension calculates the incidents percentage for a given list of queries and all the incidents.
*
* @author Xidong Liu <xliu035@gmail.com>
*/
import java.util.*;
public class IncidentsCalculationExtension {
@maydayco
maydayco / gist:5714455
Last active December 18, 2015 02:58
Binary Tree Traversal
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {